diff --git a/src/panels/lovelace/components/notifications/hui-notification-item.js b/src/panels/lovelace/components/notifications/hui-notification-item.js deleted file mode 100644 index 66ed2f2a2a..0000000000 --- a/src/panels/lovelace/components/notifications/hui-notification-item.js +++ /dev/null @@ -1,35 +0,0 @@ -import { PolymerElement } from "@polymer/polymer/polymer-element"; -import computeDomain from "../../../../common/entity/compute_domain"; - -import "./hui-configurator-notification-item"; -import "./hui-persistent-notification-item"; - -export class HuiNotificationItem extends PolymerElement { - static get properties() { - return { - hass: Object, - notification: { - type: Object, - observer: "_stateChanged", - }, - }; - } - - _stateChanged(notification) { - if (this.lastChild) { - this.removeChild(this.lastChild); - } - - if (!notification) return; - - const domain = notification.entity_id - ? computeDomain(notification.entity_id) - : "persistent_notification"; - const tag = `hui-${domain}-notification-item`; - const el = document.createElement(tag); - el.hass = this.hass; - el.notification = notification; - this.appendChild(el); - } -} -customElements.define("hui-notification-item", HuiNotificationItem); diff --git a/src/panels/lovelace/components/notifications/hui-notification-item.ts b/src/panels/lovelace/components/notifications/hui-notification-item.ts new file mode 100644 index 0000000000..0aa39a4e4d --- /dev/null +++ b/src/panels/lovelace/components/notifications/hui-notification-item.ts @@ -0,0 +1,55 @@ +import { + LitElement, + property, + customElement, + PropertyValues, + TemplateResult, + html, +} from "lit-element"; + +import "./hui-configurator-notification-item"; +import "./hui-persistent-notification-item"; + +import { HassEntity } from "home-assistant-js-websocket"; +import { HomeAssistant } from "../../../../types"; + +@customElement("hui-notification-item") +export class HuiNotificationItem extends LitElement { + @property() public hass?: HomeAssistant; + + @property() public notification?: HassEntity; + + protected shouldUpdate(changedProps: PropertyValues): boolean { + if (!this.hass || !this.notification || changedProps.has("notification")) { + return true; + } + + return false; + } + + protected render(): TemplateResult | void { + if (!this.hass || !this.notification) { + return html``; + } + + return this.notification.entity_id + ? html` + + ` + : html` + + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-notification-item": HuiNotificationItem; + } +} diff --git a/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js b/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js index d763ab3838..30ee92adc1 100644 --- a/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js +++ b/src/panels/lovelace/components/notifications/hui-persistent-notification-item.js @@ -87,6 +87,6 @@ export class HuiPersistentNotificationItem extends LocalizeMixin( } } customElements.define( - "hui-persistent_notification-notification-item", + "hui-persistent-notification-item", HuiPersistentNotificationItem );