Fix timer entity exception (#11837)

This commit is contained in:
Paulus Schoutsen 2022-02-24 10:30:45 -08:00 committed by GitHub
parent 02d058561b
commit b7c149fcc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,18 @@ class HuiTimerEntityRow extends LitElement {
throw new Error("Invalid configuration"); throw new Error("Invalid configuration");
} }
this._config = config; 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 { public disconnectedCallback(): void {
@ -75,7 +87,9 @@ class HuiTimerEntityRow extends LitElement {
protected updated(changedProps: PropertyValues) { protected updated(changedProps: PropertyValues) {
super.updated(changedProps); super.updated(changedProps);
if (changedProps.has("hass")) { if (!this._config || !changedProps.has("hass")) {
return;
}
const stateObj = this.hass!.states[this._config!.entity]; const stateObj = this.hass!.states[this._config!.entity];
const oldHass = changedProps.get("hass") as this["hass"]; const oldHass = changedProps.get("hass") as this["hass"];
const oldStateObj = oldHass const oldStateObj = oldHass
@ -88,7 +102,6 @@ class HuiTimerEntityRow extends LitElement {
this._clearInterval(); this._clearInterval();
} }
} }
}
private _clearInterval(): void { private _clearInterval(): void {
if (this._interval) { if (this._interval) {