From 6bb3b843776aeb28ac3bf4e579a3e2cdc5bee785 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 22 May 2020 15:36:30 +0200 Subject: [PATCH] Fix device entities not updating (#5983) --- .../device-detail/ha-device-entities-card.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index b82d7e4dd0..a586d15f5a 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -9,7 +9,6 @@ import { LitElement, property, PropertyValues, - queryAll, TemplateResult, } from "lit-element"; import { computeDomain } from "../../../../common/entity/compute_domain"; @@ -23,6 +22,7 @@ import { addEntitiesToLovelaceView } from "../../../lovelace/editor/add-entities import { LovelaceRow } from "../../../lovelace/entity-rows/types"; import { showEntityEditorDialog } from "../../entities/show-dialog-entity-editor"; import { EntityRegistryStateEntry } from "../ha-config-device-page"; +import { HuiErrorCard } from "../../../lovelace/cards/hui-error-card"; @customElement("ha-device-entities-card") export class HaDeviceEntitiesCard extends LitElement { @@ -32,20 +32,21 @@ export class HaDeviceEntitiesCard extends LitElement { @property() private _showDisabled = false; - @queryAll("#entities > *") private _entityRows?: LovelaceRow[]; + private _entityRows: Array = []; protected shouldUpdate(changedProps: PropertyValues) { - if (changedProps.has("hass")) { - this._entityRows?.forEach((element) => { + if (changedProps.has("hass") && changedProps.size === 1) { + this._entityRows.forEach((element) => { element.hass = this.hass; }); - return changedProps.size > 1; + return false; } return true; } protected render(): TemplateResult { const disabledEntities: EntityRegistryStateEntry[] = []; + this._entityRows = []; return html` ${this.entities.length ? html` -
+
${this.entities.map((entry: EntityRegistryStateEntry) => { if (entry.disabled_by) { disabledEntities.push(entry); @@ -127,8 +128,7 @@ export class HaDeviceEntitiesCard extends LitElement { } // @ts-ignore element.entry = entry; - element.addEventListener("hass-more-info", (ev) => this._openEditEntry(ev)); - + this._entityRows.push(element); return html`
${element}
`; } @@ -148,8 +148,16 @@ export class HaDeviceEntitiesCard extends LitElement { `; } - private _openEditEntry(ev: Event): void { + private _overrideMoreInfo(ev: Event): void { ev.stopPropagation(); + const entry = (ev.target! as any).entry; + showEntityEditorDialog(this, { + entry, + entity_id: entry.entity_id, + }); + } + + private _openEditEntry(ev: Event): void { const entry = (ev.currentTarget! as any).entry; showEntityEditorDialog(this, { entry, @@ -173,7 +181,7 @@ export class HaDeviceEntitiesCard extends LitElement { display: block; } ha-icon { - width: 40px; + margin-left: 8px; } .entity-id { color: var(--secondary-text-color);