Allow multiple connections per browser

This commit is contained in:
Thomas Lovén 2022-07-24 19:04:52 +00:00
parent 1cb64a2c8d
commit 1076bb2c9c
3 changed files with 18 additions and 27 deletions

View File

@ -24,7 +24,7 @@ class BrowserModBrowser:
self.entities = {} self.entities = {}
self.data = {} self.data = {}
self.settings = {} self.settings = {}
self.connection = None self._connections = []
self.update_entities(hass) self.update_entities(hass)
@ -105,17 +105,16 @@ class BrowserModBrowser:
if self.connection is None: if self.connection is None:
return return
connection, cid = self.connection for (connection, cid) in self.connection:
connection.send_message(
connection.send_message( event_message(
event_message( cid,
cid, {
{ "command": command,
"command": command, **kwargs,
**kwargs, },
}, )
) )
)
def delete(self, hass): def delete(self, hass):
"""Delete browser and associated entities.""" """Delete browser and associated entities."""
@ -130,6 +129,14 @@ class BrowserModBrowser:
device = dr.async_get_device({(DOMAIN, self.browserID)}) device = dr.async_get_device({(DOMAIN, self.browserID)})
dr.async_remove_device(device.id) dr.async_remove_device(device.id)
@property
def connection(self):
return self._connections
@connection.setter
def connection(self, con):
self._connections.append(con)
def getBrowser(hass, browserID, *, create=True): def getBrowser(hass, browserID, *, create=True):
"""Get or create browser by browserID.""" """Get or create browser by browserID."""

View File

@ -1918,14 +1918,6 @@ const AutoSettingsMixin = (SuperClass) => {
return link === null || link === void 0 ? void 0 : link.href; return link === null || link === void 0 ? void 0 : link.href;
} }
_updateFavicon({ result }) { _updateFavicon({ result }) {
// TEMP: Template for testing
/*
{% if is_state("light.bed_light", "on") %}
/local/workspace/test/icons/green.png
{% else %}
/local/workspace/test/icons/red.png
{% endif %}
*/
const link = document.head.querySelector("link[rel~='icon']"); const link = document.head.querySelector("link[rel~='icon']");
link.href = result; link.href = result;
window.browser_mod.fireEvent("browser-mod-favicon-update"); window.browser_mod.fireEvent("browser-mod-favicon-update");

View File

@ -109,14 +109,6 @@ export const AutoSettingsMixin = (SuperClass) => {
} }
_updateFavicon({ result }) { _updateFavicon({ result }) {
// TEMP: Template for testing
/*
{% if is_state("light.bed_light", "on") %}
/local/workspace/test/icons/green.png
{% else %}
/local/workspace/test/icons/red.png
{% endif %}
*/
const link: any = document.head.querySelector("link[rel~='icon']"); const link: any = document.head.querySelector("link[rel~='icon']");
link.href = result; link.href = result;
window.browser_mod.fireEvent("browser-mod-favicon-update"); window.browser_mod.fireEvent("browser-mod-favicon-update");