From b7c149fcc14322a11689bab79b0cb938ab7a9e97 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 24 Feb 2022 10:30:45 -0800 Subject: [PATCH] Fix timer entity exception (#11837) --- .../entity-rows/hui-timer-entity-row.ts | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/panels/lovelace/entity-rows/hui-timer-entity-row.ts b/src/panels/lovelace/entity-rows/hui-timer-entity-row.ts index a06eeb9905..a557406ad1 100644 --- a/src/panels/lovelace/entity-rows/hui-timer-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-timer-entity-row.ts @@ -23,6 +23,18 @@ class HuiTimerEntityRow extends LitElement { throw new Error("Invalid configuration"); } this._config = config; + + if (!this.hass) { + return; + } + + const stateObj = this.hass!.states[this._config.entity]; + + if (stateObj) { + this._startInterval(stateObj); + } else { + this._clearInterval(); + } } public disconnectedCallback(): void { @@ -75,18 +87,19 @@ class HuiTimerEntityRow extends LitElement { protected updated(changedProps: PropertyValues) { super.updated(changedProps); - if (changedProps.has("hass")) { - const stateObj = this.hass!.states[this._config!.entity]; - const oldHass = changedProps.get("hass") as this["hass"]; - const oldStateObj = oldHass - ? oldHass.states[this._config!.entity] - : undefined; + if (!this._config || !changedProps.has("hass")) { + return; + } + const stateObj = this.hass!.states[this._config!.entity]; + const oldHass = changedProps.get("hass") as this["hass"]; + const oldStateObj = oldHass + ? oldHass.states[this._config!.entity] + : undefined; - if (oldStateObj !== stateObj) { - this._startInterval(stateObj); - } else if (!stateObj) { - this._clearInterval(); - } + if (oldStateObj !== stateObj) { + this._startInterval(stateObj); + } else if (!stateObj) { + this._clearInterval(); } }