From 23cbdaef2db3ac1f3b05254c38bf487cec869f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 24 Jul 2022 23:41:37 +0000 Subject: [PATCH] Tweak popup timing --- custom_components/browser_mod/browser_mod.js | 36 ++++++++++++++------ js/plugin/main.ts | 2 ++ js/plugin/popups.ts | 30 ++++++++++------ js/plugin/services.ts | 4 +++ 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index 57f3647..1382266 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -947,6 +947,7 @@ const ServicesMixin = (SuperClass) => { data: [title: ] [content: ] + [size: ] [right_button: ] [right_button_action: ] [left_button: ] @@ -955,6 +956,7 @@ const ServicesMixin = (SuperClass) => { [dismiss_action: ] [timeout: ] [timeout_action: ] + [style: ] More-info: service: browser_mod.more_info @@ -1013,7 +1015,11 @@ 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(".")) { + // CALL HOME ASSISTANT SERVICE + const [domain, srv] = _service.split("."); + return this.hass.callService(domain, srv, data); + } if (_service.startsWith("browser_mod.")) { _service = _service.substring(12); } @@ -1114,8 +1120,14 @@ const t={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e */class e extends i{constructor(i){if(super(i),this.it=w,i.type!==t.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(r){if(r===w||null==r)return this.ft=void 0,this.it=r;if(r===b)return r;if("string"!=typeof r)throw Error(this.constructor.directiveName+"() called with a non-string value");if(r===this.it)return this.ft;this.it=r;const s=[r];return s.raw=s,this.ft={_$litType$:this.constructor.resultType,strings:s,values:[]}}}e.directiveName="unsafeHTML",e.resultType=1;const o=e$1(e); class BrowserModPopup extends s { - closeDialog() { + closedCallback() { + var _a; + (_a = this._resolveClosed) === null || _a === void 0 ? void 0 : _a.call(this); + this._resolveClosed = undefined; + } + async closeDialog() { this.open = false; + await new Promise((resolve) => (this._resolveClosed = resolve)); clearInterval(this._timeoutTimer); } openDialog() { @@ -1162,30 +1174,30 @@ class BrowserModPopup extends s { this.fullscreen = size === "fullscreen" ? "" : undefined; this._style = style; } - _primary() { + async _primary() { var _a, _b, _c; if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); (_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.right_button_action) === null || _c === void 0 ? void 0 : _c.call(_b); } - _secondary() { + async _secondary() { var _a, _b, _c; if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); (_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.left_button_action) === null || _c === void 0 ? void 0 : _c.call(_b); } - _dismiss() { + async _dismiss() { var _a, _b; - this.closeDialog(); + await this.closeDialog(); (_b = (_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action) === null || _b === void 0 ? void 0 : _b.call(_a); } - _timeout() { + async _timeout() { var _a, _b, _c; if ((_a = this._actions) === null || _a === void 0 ? void 0 : _a.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); (_c = (_b = this._actions) === null || _b === void 0 ? void 0 : _b.timeout_action) === null || _c === void 0 ? void 0 : _c.call(_b); } render() { @@ -1194,7 +1206,7 @@ class BrowserModPopup extends s { return $ ` { 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 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 ed1414e..a5568bd 100644 --- a/js/plugin/main.ts +++ b/js/plugin/main.ts @@ -32,6 +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 Rename browser_mod commands to browser_mod services x Framework x ll-custom handling diff --git a/js/plugin/popups.ts b/js/plugin/popups.ts index 26f19e2..e085c22 100644 --- a/js/plugin/popups.ts +++ b/js/plugin/popups.ts @@ -3,6 +3,8 @@ import { property } from "lit/decorators.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; import { provideHass, loadLoadCardHelpers, hass_base_el } from "../helpers"; +let aaa = 0; + class BrowserModPopup extends LitElement { @property() open; @property() content; @@ -20,8 +22,16 @@ class BrowserModPopup extends LitElement { _timeoutTimer; @property() _style; - closeDialog() { + _resolveClosed; + + closedCallback() { + this._resolveClosed?.(); + this._resolveClosed = undefined; + } + + async closeDialog() { this.open = false; + await new Promise((resolve) => (this._resolveClosed = resolve)); clearInterval(this._timeoutTimer); } @@ -86,23 +96,23 @@ class BrowserModPopup extends LitElement { this._style = style; } - _primary() { + async _primary() { if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); this._actions?.right_button_action?.(); } - _secondary() { + async _secondary() { if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); this._actions?.left_button_action?.(); } - _dismiss() { - this.closeDialog(); + async _dismiss() { + await this.closeDialog(); this._actions?.dismiss_action?.(); } - _timeout() { + async _timeout() { if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; - this.closeDialog(); + await this.closeDialog(); this._actions?.timeout_action?.(); } @@ -112,7 +122,7 @@ class BrowserModPopup extends LitElement { return html` { data: [title: ] [content: ] + [size: ] [right_button: ] [right_button_action: ] [left_button: ] @@ -31,6 +32,7 @@ export const ServicesMixin = (SuperClass) => { [dismiss_action: ] [timeout: ] [timeout_action: ] + [style: ] More-info: service: browser_mod.more_info @@ -95,6 +97,8 @@ export const ServicesMixin = (SuperClass) => { let _service: String = service; if (!_service.startsWith("browser_mod.") && _service.includes(".")) { // CALL HOME ASSISTANT SERVICE + const [domain, srv] = _service.split("."); + return this.hass.callService(domain, srv, data); } if (_service.startsWith("browser_mod.")) {