From be4e45c22cc0c86dd6b72b9bf2ffd2e579059c31 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sun, 6 Oct 2019 23:08:14 -0500 Subject: [PATCH 1/2] picture-glance: check for entity state change --- src/panels/lovelace/cards/hui-picture-glance-card.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/panels/lovelace/cards/hui-picture-glance-card.ts b/src/panels/lovelace/cards/hui-picture-glance-card.ts index 58992f7afa..2aa9f36b72 100644 --- a/src/panels/lovelace/cards/hui-picture-glance-card.ts +++ b/src/panels/lovelace/cards/hui-picture-glance-card.ts @@ -95,6 +95,15 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard { return true; } + if ( + this._config && + this._config.entity && + oldHass.states[this._config.entity] !== + this.hass!.states[this._config.entity] + ) { + return true; + } + if (this._entitiesDialog) { for (const entity of this._entitiesDialog) { if ( From 55d2a3c8b1ee1e5daf6076a370380b2611561424 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sun, 6 Oct 2019 23:16:14 -0500 Subject: [PATCH 2/2] simplify --- .../lovelace/cards/hui-picture-glance-card.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/panels/lovelace/cards/hui-picture-glance-card.ts b/src/panels/lovelace/cards/hui-picture-glance-card.ts index 2aa9f36b72..abc489358c 100644 --- a/src/panels/lovelace/cards/hui-picture-glance-card.ts +++ b/src/panels/lovelace/cards/hui-picture-glance-card.ts @@ -27,6 +27,7 @@ import { longPress } from "../common/directives/long-press-directive"; import { processConfigEntities } from "../common/process-config-entities"; import { handleClick } from "../common/handle-click"; import { PictureGlanceCardConfig, ConfigEntity } from "./types"; +import { hasConfigOrEntityChanged } from "../common/has-changed"; const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]); @@ -86,28 +87,16 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard { } protected shouldUpdate(changedProps: PropertyValues): boolean { - if (changedProps.has("_config")) { + if (hasConfigOrEntityChanged(this, changedProps)) { return true; } const oldHass = changedProps.get("hass") as HomeAssistant | undefined; - if (!oldHass) { - return true; - } - - if ( - this._config && - this._config.entity && - oldHass.states[this._config.entity] !== - this.hass!.states[this._config.entity] - ) { - return true; - } if (this._entitiesDialog) { for (const entity of this._entitiesDialog) { if ( - oldHass.states[entity.entity] !== this.hass!.states[entity.entity] + oldHass!.states[entity.entity] !== this.hass!.states[entity.entity] ) { return true; } @@ -117,7 +106,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard { if (this._entitiesToggle) { for (const entity of this._entitiesToggle) { if ( - oldHass.states[entity.entity] !== this.hass!.states[entity.entity] + oldHass!.states[entity.entity] !== this.hass!.states[entity.entity] ) { return true; }