update hasChanged for formatEntityState, fix glance card shouldUpdate (#17854)

This commit is contained in:
karwosts 2023-09-08 06:54:11 -07:00 committed by GitHub
parent 4a6539d75b
commit 7176a51fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 22 deletions

View File

@ -35,6 +35,7 @@ import { createEntityNotFoundWarning } from "../components/hui-warning";
import "../components/hui-warning-element"; import "../components/hui-warning-element";
import { LovelaceCard, LovelaceCardEditor } from "../types"; import { LovelaceCard, LovelaceCardEditor } from "../types";
import { GlanceCardConfig, GlanceConfigEntity } from "./types"; import { GlanceCardConfig, GlanceConfigEntity } from "./types";
import { hasConfigOrEntitiesChanged } from "../common/has-changed";
@customElement("hui-glance-card") @customElement("hui-glance-card")
export class HuiGlanceCard extends LitElement implements LovelaceCard { export class HuiGlanceCard extends LitElement implements LovelaceCard {
@ -121,28 +122,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
} }
protected shouldUpdate(changedProps: PropertyValues): boolean { protected shouldUpdate(changedProps: PropertyValues): boolean {
if (changedProps.has("_config")) { return hasConfigOrEntitiesChanged(this, changedProps);
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;
} }
protected render() { protected render() {

View File

@ -22,6 +22,11 @@ export function hasConfigChanged(
oldHass.themes !== element.hass!.themes || oldHass.themes !== element.hass!.themes ||
oldHass.locale !== element.hass!.locale || oldHass.locale !== element.hass!.locale ||
oldHass.localize !== element.hass.localize || 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 oldHass.config.state !== element.hass.config.state
) { ) {
return true; return true;