mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 08:15:49 +00:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -671,10 +671,15 @@ async def write_image(config, all_frames=False):
|
||||
resize = config.get(CONF_RESIZE)
|
||||
if is_svg_file(path):
|
||||
# Local import so use of non-SVG files needn't require cairosvg installed
|
||||
from pyexpat import ExpatError
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
||||
from cairosvg import svg2png
|
||||
from cairosvg.helpers import PointError
|
||||
|
||||
if not resize:
|
||||
resize = (None, None)
|
||||
try:
|
||||
with open(path, "rb") as file:
|
||||
image = svg2png(
|
||||
file_obj=file,
|
||||
@@ -683,6 +688,16 @@ async def write_image(config, all_frames=False):
|
||||
)
|
||||
image = Image.open(io.BytesIO(image))
|
||||
width, height = image.size
|
||||
except (
|
||||
ValueError,
|
||||
ParseError,
|
||||
IndexError,
|
||||
ExpatError,
|
||||
AttributeError,
|
||||
TypeError,
|
||||
PointError,
|
||||
) as e:
|
||||
raise core.EsphomeError(f"Could not load SVG image {path}: {e}") from e
|
||||
else:
|
||||
image = Image.open(path)
|
||||
width, height = image.size
|
||||
|
||||
@@ -220,18 +220,16 @@ void DeferredUpdateEventSourceList::add_new_client(WebServer *ws, AsyncWebServer
|
||||
DeferredUpdateEventSource *es = new DeferredUpdateEventSource(ws, "/events");
|
||||
this->push_back(es);
|
||||
|
||||
es->onConnect([this, ws, es](AsyncEventSourceClient *client) {
|
||||
ws->defer([this, ws, es]() { this->on_client_connect_(ws, es); });
|
||||
});
|
||||
es->onConnect([this, es](AsyncEventSourceClient *client) { this->on_client_connect_(es); });
|
||||
|
||||
es->onDisconnect([this, ws, es](AsyncEventSourceClient *client) {
|
||||
ws->defer([this, es]() { this->on_client_disconnect_((DeferredUpdateEventSource *) es); });
|
||||
});
|
||||
es->onDisconnect([this, es](AsyncEventSourceClient *client) { this->on_client_disconnect_(es); });
|
||||
|
||||
es->handleRequest(request);
|
||||
}
|
||||
|
||||
void DeferredUpdateEventSourceList::on_client_connect_(WebServer *ws, DeferredUpdateEventSource *source) {
|
||||
void DeferredUpdateEventSourceList::on_client_connect_(DeferredUpdateEventSource *source) {
|
||||
WebServer *ws = source->web_server_;
|
||||
ws->defer([this, ws, source]() {
|
||||
// Configure reconnect timeout and send config
|
||||
// this should always go through since the AsyncEventSourceClient event queue is empty on connect
|
||||
std::string message = ws->get_config_json();
|
||||
@@ -257,13 +255,16 @@ void DeferredUpdateEventSourceList::on_client_connect_(WebServer *ws, DeferredUp
|
||||
// while(!source->entities_iterator_.completed()) {
|
||||
// source->entities_iterator_.advance();
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
void DeferredUpdateEventSourceList::on_client_disconnect_(DeferredUpdateEventSource *source) {
|
||||
source->web_server_->defer([this, source]() {
|
||||
// This method was called via WebServer->defer() and is no longer executing in the
|
||||
// context of the network callback. The object is now dead and can be safely deleted.
|
||||
this->remove(source);
|
||||
delete source; // NOLINT
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ class DeferredUpdateEventSource : public AsyncEventSource {
|
||||
|
||||
class DeferredUpdateEventSourceList : public std::list<DeferredUpdateEventSource *> {
|
||||
protected:
|
||||
void on_client_connect_(WebServer *ws, DeferredUpdateEventSource *source);
|
||||
void on_client_connect_(DeferredUpdateEventSource *source);
|
||||
void on_client_disconnect_(DeferredUpdateEventSource *source);
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user