From 1076bb2c9cdb2fb802809a1873eaa481b9c6755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 24 Jul 2022 19:04:52 +0000 Subject: [PATCH] Allow multiple connections per browser --- custom_components/browser_mod/browser.py | 29 ++++++++++++-------- custom_components/browser_mod/browser_mod.js | 8 ------ js/plugin/frontend-settings.ts | 8 ------ 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/custom_components/browser_mod/browser.py b/custom_components/browser_mod/browser.py index b3971aa..25d47dc 100644 --- a/custom_components/browser_mod/browser.py +++ b/custom_components/browser_mod/browser.py @@ -24,7 +24,7 @@ class BrowserModBrowser: self.entities = {} self.data = {} self.settings = {} - self.connection = None + self._connections = [] self.update_entities(hass) @@ -105,17 +105,16 @@ class BrowserModBrowser: if self.connection is None: return - connection, cid = self.connection - - connection.send_message( - event_message( - cid, - { - "command": command, - **kwargs, - }, + for (connection, cid) in self.connection: + connection.send_message( + event_message( + cid, + { + "command": command, + **kwargs, + }, + ) ) - ) def delete(self, hass): """Delete browser and associated entities.""" @@ -130,6 +129,14 @@ class BrowserModBrowser: device = dr.async_get_device({(DOMAIN, self.browserID)}) 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): """Get or create browser by browserID.""" diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index 5f0d0c2..f133b7f 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -1918,14 +1918,6 @@ const AutoSettingsMixin = (SuperClass) => { return link === null || link === void 0 ? void 0 : link.href; } _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']"); link.href = result; window.browser_mod.fireEvent("browser-mod-favicon-update"); diff --git a/js/plugin/frontend-settings.ts b/js/plugin/frontend-settings.ts index eccb9ed..d796248 100644 --- a/js/plugin/frontend-settings.ts +++ b/js/plugin/frontend-settings.ts @@ -109,14 +109,6 @@ export const AutoSettingsMixin = (SuperClass) => { } _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']"); link.href = result; window.browser_mod.fireEvent("browser-mod-favicon-update");