diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index 4ecd630..0264b23 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -887,6 +887,13 @@ const ServicesMixin = (SuperClass) => { [timeout: ] [timeout_action: ] + More-info: + service: browser_mod.more_info + data: + entity: + [large: ] + [ignore_popup_card: ] + Close popup: service: browser_mod.close_popup @@ -914,6 +921,7 @@ const ServicesMixin = (SuperClass) => { "sequence", "delay", "popup", + "more_info", "close_popup", "navigate", "refresh", @@ -948,6 +956,10 @@ const ServicesMixin = (SuperClass) => { case "delay": await new Promise((resolve) => setTimeout(resolve, data.time)); break; + case "more_info": + const { entity, large, ignore_popup_card } = data; + this.showMoreInfo(entity, large, ignore_popup_card); + break; case "popup": const { title, content } = data, d = __rest(data, ["title", "content"]); for (const [k, v] of Object.entries(d)) { @@ -1332,6 +1344,22 @@ const PopupMixin = (SuperClass) => { } closePopup(...args) { this._popupEl.closeDialog(); + this.showMoreInfo(""); + } + async showMoreInfo(entityId, large = false, ignore_popup_card = undefined) { + const base = await hass_base_el(); + base.dispatchEvent(new CustomEvent("hass-more-info", { + bubbles: true, + composed: true, + cancelable: false, + detail: { entityId, ignore_popup_card }, + })); + if (large) { + await new Promise((resolve) => setTimeout(resolve, 50)); + const dialog = base.shadowRoot.querySelector("ha-more-info-dialog"); + if (dialog) + dialog.large = true; + } } }; }; @@ -1670,18 +1698,19 @@ class PopupCard extends s { window.removeEventListener("hass-more-info", this.popup); } popup(ev) { - var _a, _b; - if (((_a = ev.detail) === null || _a === void 0 ? void 0 : _a.entityId) === this._config.entity) { + var _a, _b, _c; + if (((_a = ev.detail) === null || _a === void 0 ? void 0 : _a.entityId) === this._config.entity && + !((_b = ev.detail) === null || _b === void 0 ? void 0 : _b.ignore_popup_card)) { ev.stopPropagation(); ev.preventDefault(); const config = Object.assign({}, this._config); delete config.card; - (_b = window.browser_mod) === null || _b === void 0 ? void 0 : _b.service("popup", Object.assign({ content: this._config.card }, this._config)); + (_c = window.browser_mod) === null || _c === void 0 ? void 0 : _c.service("popup", Object.assign({ content: this._config.card }, this._config)); setTimeout(() => this.dispatchEvent(new CustomEvent("hass-more-info", { bubbles: true, composed: true, cancelable: false, - detail: { entityID: "." }, + detail: { entityId: "." }, })), 50); } } @@ -1761,7 +1790,7 @@ __decorate([ - Commands x popup x close_popup - - more-info + x more-info x navigate - lovelace-reload? x window-reload diff --git a/custom_components/browser_mod/service.py b/custom_components/browser_mod/service.py index 267d6eb..1ec4cb5 100644 --- a/custom_components/browser_mod/service.py +++ b/custom_components/browser_mod/service.py @@ -62,6 +62,7 @@ async def async_setup_services(hass): hass.services.async_register(DOMAIN, "sequence", handle_service) hass.services.async_register(DOMAIN, "delay", handle_service) hass.services.async_register(DOMAIN, "popup", handle_service) + hass.services.async_register(DOMAIN, "more_info", handle_service) hass.services.async_register(DOMAIN, "close_popup", handle_service) hass.services.async_register(DOMAIN, "navigate", handle_service) hass.services.async_register(DOMAIN, "refresh", handle_service) diff --git a/custom_components/browser_mod/services.yaml b/custom_components/browser_mod/services.yaml index 1b1cd25..2981c2a 100644 --- a/custom_components/browser_mod/services.yaml +++ b/custom_components/browser_mod/services.yaml @@ -113,6 +113,35 @@ popup: selector: object: +more_info: + description: "Show more-info dialog" + target: + device: + integration: "browser_mod" + multiple: true + entity: + integration: "browser_mod_none" + area: + device: + integration: "browser_mod" + multiple: true + fields: + entity: + name: Entity ID + required: true + selector: + text: + large: + name: Large size + default: false + selector: + boolean: + ignore_popup_card: + name: Ignore any active popup-card overrides + default: false + selector: + boolean: + close_popup: description: "Close a popup" target: diff --git a/js/plugin/main.ts b/js/plugin/main.ts index 7215945..11879a4 100644 --- a/js/plugin/main.ts +++ b/js/plugin/main.ts @@ -36,7 +36,7 @@ import "./popup-card"; - Commands x popup x close_popup - - more-info + x more-info x navigate - lovelace-reload? x window-reload diff --git a/js/plugin/popup-card.ts b/js/plugin/popup-card.ts index a5deea0..134322e 100644 --- a/js/plugin/popup-card.ts +++ b/js/plugin/popup-card.ts @@ -52,7 +52,10 @@ class PopupCard extends LitElement { } popup(ev: CustomEvent) { - if (ev.detail?.entityId === this._config.entity) { + if ( + ev.detail?.entityId === this._config.entity && + !ev.detail?.ignore_popup_card + ) { ev.stopPropagation(); ev.preventDefault(); const config = { ...this._config }; @@ -69,7 +72,7 @@ class PopupCard extends LitElement { bubbles: true, composed: true, cancelable: false, - detail: { entityID: "." }, + detail: { entityId: "." }, }) ), 50 diff --git a/js/plugin/popups.ts b/js/plugin/popups.ts index ee5d1ad..294f7fd 100644 --- a/js/plugin/popups.ts +++ b/js/plugin/popups.ts @@ -1,7 +1,7 @@ import { LitElement, html, css } from "lit"; import { property } from "lit/decorators.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; -import { provideHass, loadLoadCardHelpers } from "../helpers"; +import { provideHass, loadLoadCardHelpers, hass_base_el } from "../helpers"; class BrowserModPopup extends LitElement { @property() open; @@ -309,6 +309,26 @@ export const PopupMixin = (SuperClass) => { closePopup(...args) { this._popupEl.closeDialog(); + this.showMoreInfo(""); + } + + async showMoreInfo(entityId, large = false, ignore_popup_card = undefined) { + const base = await hass_base_el(); + base.dispatchEvent( + new CustomEvent("hass-more-info", { + bubbles: true, + composed: true, + cancelable: false, + detail: { entityId, ignore_popup_card }, + }) + ); + if (large) { + await new Promise((resolve) => setTimeout(resolve, 50)); + const dialog: any = base.shadowRoot.querySelector( + "ha-more-info-dialog" + ); + if (dialog) dialog.large = true; + } } }; }; diff --git a/js/plugin/services.ts b/js/plugin/services.ts index a163d07..97dcd4d 100644 --- a/js/plugin/services.ts +++ b/js/plugin/services.ts @@ -32,6 +32,13 @@ export const ServicesMixin = (SuperClass) => { [timeout: ] [timeout_action: ] + More-info: + service: browser_mod.more_info + data: + entity: + [large: ] + [ignore_popup_card: ] + Close popup: service: browser_mod.close_popup @@ -60,6 +67,7 @@ export const ServicesMixin = (SuperClass) => { "sequence", "delay", "popup", + "more_info", "close_popup", "navigate", "refresh", @@ -101,6 +109,11 @@ export const ServicesMixin = (SuperClass) => { await new Promise((resolve) => setTimeout(resolve, data.time)); break; + case "more_info": + const { entity, large, ignore_popup_card } = data; + this.showMoreInfo(entity, large, ignore_popup_card); + break; + case "popup": const { title, content, ...d } = data; for (const [k, v] of Object.entries(d)) {