From 7176a51fec8ecc69decc588c4a0c5166aeb8218e Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Fri, 8 Sep 2023 06:54:11 -0700 Subject: [PATCH] update hasChanged for formatEntityState, fix glance card shouldUpdate (#17854) --- src/panels/lovelace/cards/hui-glance-card.ts | 24 ++------------------ src/panels/lovelace/common/has-changed.ts | 5 ++++ 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/panels/lovelace/cards/hui-glance-card.ts b/src/panels/lovelace/cards/hui-glance-card.ts index 7a4fef8dc8a0..6ccad438e31e 100644 --- a/src/panels/lovelace/cards/hui-glance-card.ts +++ b/src/panels/lovelace/cards/hui-glance-card.ts @@ -35,6 +35,7 @@ import { createEntityNotFoundWarning } from "../components/hui-warning"; import "../components/hui-warning-element"; import { LovelaceCard, LovelaceCardEditor } from "../types"; import { GlanceCardConfig, GlanceConfigEntity } from "./types"; +import { hasConfigOrEntitiesChanged } from "../common/has-changed"; @customElement("hui-glance-card") export class HuiGlanceCard extends LitElement implements LovelaceCard { @@ -121,28 +122,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { } protected shouldUpdate(changedProps: PropertyValues): boolean { - if (changedProps.has("_config")) { - return true; - } - - const oldHass = changedProps.get("hass") as HomeAssistant | undefined; - - if ( - !this._configEntities || - !oldHass || - oldHass.themes !== this.hass!.themes || - oldHass.locale !== this.hass!.locale - ) { - return true; - } - - for (const entity of this._configEntities) { - if (oldHass.states[entity.entity] !== this.hass!.states[entity.entity]) { - return true; - } - } - - return false; + return hasConfigOrEntitiesChanged(this, changedProps); } protected render() { diff --git a/src/panels/lovelace/common/has-changed.ts b/src/panels/lovelace/common/has-changed.ts index 1abf9d11ffd7..e2c60803e633 100644 --- a/src/panels/lovelace/common/has-changed.ts +++ b/src/panels/lovelace/common/has-changed.ts @@ -22,6 +22,11 @@ export function hasConfigChanged( oldHass.themes !== element.hass!.themes || oldHass.locale !== element.hass!.locale || oldHass.localize !== element.hass.localize || + oldHass.formatEntityState !== element.hass.formatEntityState || + oldHass.formatEntityAttributeName !== + element.hass.formatEntityAttributeName || + oldHass.formatEntityAttributeValue !== + element.hass.formatEntityAttributeValue || oldHass.config.state !== element.hass.config.state ) { return true;