From 8dbd00aa0fafeafb7393aa462e4275136c4ad3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 25 Jul 2022 00:00:02 +0000 Subject: [PATCH] Forward browser_id in service calls from frontend --- custom_components/browser_mod/browser_mod.js | 12 ++++++++---- js/plugin/main.ts | 4 ++-- js/plugin/services.ts | 9 +++++++-- test/configuration.yaml | 5 +++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index 1382266..8479c80 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -1015,10 +1015,14 @@ const ServicesMixin = (SuperClass) => { } async _service_action({ service, data }) { let _service = service; - if (!_service.startsWith("browser_mod.") && _service.includes(".")) { + if ((!_service.startsWith("browser_mod.") && _service.includes(".")) || + data.browser_id !== undefined) { + const d = Object.assign({}, data); + if (d.browser_id === "THIS") + d.browser_id = this.browserID; // CALL HOME ASSISTANT SERVICE const [domain, srv] = _service.split("."); - return this.hass.callService(domain, srv, data); + return this.hass.callService(domain, srv, d); } if (_service.startsWith("browser_mod.")) { _service = _service.substring(12); @@ -2101,8 +2105,8 @@ const BrowserIDMixin = (SuperClass) => { x Information about interaction requirement x Information about fullykiosk - Commands - - Change targets from the frontend - - Send browser ID to the backend in service calls? + x Change targets from the frontend + x Send browser ID to the backend in service calls? x Rename browser_mod commands to browser_mod services x Framework x ll-custom handling diff --git a/js/plugin/main.ts b/js/plugin/main.ts index a5568bd..1327208 100644 --- a/js/plugin/main.ts +++ b/js/plugin/main.ts @@ -32,8 +32,8 @@ import { BrowserIDMixin } from "./browserID"; x Information about interaction requirement x Information about fullykiosk - Commands - - Change targets from the frontend - - Send browser ID to the backend in service calls? + x Change targets from the frontend + x Send browser ID to the backend in service calls? x Rename browser_mod commands to browser_mod services x Framework x ll-custom handling diff --git a/js/plugin/services.ts b/js/plugin/services.ts index 92a8ffb..8a46121 100644 --- a/js/plugin/services.ts +++ b/js/plugin/services.ts @@ -95,10 +95,15 @@ export const ServicesMixin = (SuperClass) => { async _service_action({ service, data }) { let _service: String = service; - if (!_service.startsWith("browser_mod.") && _service.includes(".")) { + if ( + (!_service.startsWith("browser_mod.") && _service.includes(".")) || + data.browser_id !== undefined + ) { + const d = { ...data }; + if (d.browser_id === "THIS") d.browser_id = this.browserID; // CALL HOME ASSISTANT SERVICE const [domain, srv] = _service.split("."); - return this.hass.callService(domain, srv, data); + return this.hass.callService(domain, srv, d); } if (_service.startsWith("browser_mod.")) { diff --git a/test/configuration.yaml b/test/configuration.yaml index b9879cf..54407dc 100644 --- a/test/configuration.yaml +++ b/test/configuration.yaml @@ -52,3 +52,8 @@ script: cm_debug: sequence: - service: browser_mod.debug + print_id: + sequence: + - service: system_log.write + data: + message: "Button was clicked in {{browser_id}}."