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)
|
resize = config.get(CONF_RESIZE)
|
||||||
if is_svg_file(path):
|
if is_svg_file(path):
|
||||||
# Local import so use of non-SVG files needn't require cairosvg installed
|
# 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 import svg2png
|
||||||
|
from cairosvg.helpers import PointError
|
||||||
|
|
||||||
if not resize:
|
if not resize:
|
||||||
resize = (None, None)
|
resize = (None, None)
|
||||||
|
try:
|
||||||
with open(path, "rb") as file:
|
with open(path, "rb") as file:
|
||||||
image = svg2png(
|
image = svg2png(
|
||||||
file_obj=file,
|
file_obj=file,
|
||||||
@@ -683,6 +688,16 @@ async def write_image(config, all_frames=False):
|
|||||||
)
|
)
|
||||||
image = Image.open(io.BytesIO(image))
|
image = Image.open(io.BytesIO(image))
|
||||||
width, height = image.size
|
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:
|
else:
|
||||||
image = Image.open(path)
|
image = Image.open(path)
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
|||||||
@@ -220,18 +220,16 @@ void DeferredUpdateEventSourceList::add_new_client(WebServer *ws, AsyncWebServer
|
|||||||
DeferredUpdateEventSource *es = new DeferredUpdateEventSource(ws, "/events");
|
DeferredUpdateEventSource *es = new DeferredUpdateEventSource(ws, "/events");
|
||||||
this->push_back(es);
|
this->push_back(es);
|
||||||
|
|
||||||
es->onConnect([this, ws, es](AsyncEventSourceClient *client) {
|
es->onConnect([this, es](AsyncEventSourceClient *client) { this->on_client_connect_(es); });
|
||||||
ws->defer([this, ws, es]() { this->on_client_connect_(ws, es); });
|
|
||||||
});
|
|
||||||
|
|
||||||
es->onDisconnect([this, ws, es](AsyncEventSourceClient *client) {
|
es->onDisconnect([this, es](AsyncEventSourceClient *client) { this->on_client_disconnect_(es); });
|
||||||
ws->defer([this, es]() { this->on_client_disconnect_((DeferredUpdateEventSource *) es); });
|
|
||||||
});
|
|
||||||
|
|
||||||
es->handleRequest(request);
|
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
|
// Configure reconnect timeout and send config
|
||||||
// this should always go through since the AsyncEventSourceClient event queue is empty on connect
|
// this should always go through since the AsyncEventSourceClient event queue is empty on connect
|
||||||
std::string message = ws->get_config_json();
|
std::string message = ws->get_config_json();
|
||||||
@@ -257,13 +255,16 @@ void DeferredUpdateEventSourceList::on_client_connect_(WebServer *ws, DeferredUp
|
|||||||
// while(!source->entities_iterator_.completed()) {
|
// while(!source->entities_iterator_.completed()) {
|
||||||
// source->entities_iterator_.advance();
|
// source->entities_iterator_.advance();
|
||||||
//}
|
//}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredUpdateEventSourceList::on_client_disconnect_(DeferredUpdateEventSource *source) {
|
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
|
// 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.
|
// context of the network callback. The object is now dead and can be safely deleted.
|
||||||
this->remove(source);
|
this->remove(source);
|
||||||
delete source; // NOLINT
|
delete source; // NOLINT
|
||||||
|
});
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class DeferredUpdateEventSource : public AsyncEventSource {
|
|||||||
|
|
||||||
class DeferredUpdateEventSourceList : public std::list<DeferredUpdateEventSource *> {
|
class DeferredUpdateEventSourceList : public std::list<DeferredUpdateEventSource *> {
|
||||||
protected:
|
protected:
|
||||||
void on_client_connect_(WebServer *ws, DeferredUpdateEventSource *source);
|
void on_client_connect_(DeferredUpdateEventSource *source);
|
||||||
void on_client_disconnect_(DeferredUpdateEventSource *source);
|
void on_client_disconnect_(DeferredUpdateEventSource *source);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user