diff --git a/src/cards/alarm-control-panel-card/alarm-control-panel-card.ts b/src/cards/alarm-control-panel-card/alarm-control-panel-card.ts index 4509ca5e..b0d3bfc3 100644 --- a/src/cards/alarm-control-panel-card/alarm-control-panel-card.ts +++ b/src/cards/alarm-control-panel-card/alarm-control-panel-card.ts @@ -109,9 +109,7 @@ export class AlarmControlPanelCard } async loadComponents() { - if (!this._config || !this.hass || !this._config.entity) return; - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as HassEntity | undefined; + const stateObj = this._stateObj; if (stateObj && hasCode(stateObj)) { void import("../../shared/form/mushroom-textfield"); diff --git a/src/cards/cover-card/cover-card.ts b/src/cards/cover-card/cover-card.ts index 8b00bb62..b4e1bfd2 100644 --- a/src/cards/cover-card/cover-card.ts +++ b/src/cards/cover-card/cover-card.ts @@ -142,10 +142,7 @@ export class CoverCard updatePosition() { this.position = undefined; - if (!this._config || !this.hass || !this._config.entity) return; - - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as CoverEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) return; this.position = getPosition(stateObj); @@ -166,8 +163,7 @@ export class CoverCard return nothing; } - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as CoverEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) { return this.renderNotFound(this._config); diff --git a/src/cards/light-card/light-card.ts b/src/cards/light-card/light-card.ts index ffc49655..1e40533c 100644 --- a/src/cards/light-card/light-card.ts +++ b/src/cards/light-card/light-card.ts @@ -128,10 +128,7 @@ export class LightCard updateBrightness() { this.brightness = undefined; - if (!this._config || !this.hass || !this._config.entity) return; - - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as LightEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) return; this.brightness = getBrightness(stateObj); @@ -159,8 +156,7 @@ export class LightCard return nothing; } - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as LightEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) { return this.renderNotFound(this._config); diff --git a/src/cards/media-player-card/media-player-card.ts b/src/cards/media-player-card/media-player-card.ts index 304f9162..070e638d 100644 --- a/src/cards/media-player-card/media-player-card.ts +++ b/src/cards/media-player-card/media-player-card.ts @@ -123,10 +123,7 @@ export class MediaPlayerCard updateVolume() { this.volume = undefined; - if (!this._config || !this.hass || !this._config.entity) return; - - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as MediaPlayerEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) return; const volume = getVolumeLevel(stateObj); diff --git a/src/cards/number-card/number-card.ts b/src/cards/number-card/number-card.ts index 2612007f..e7f005e2 100644 --- a/src/cards/number-card/number-card.ts +++ b/src/cards/number-card/number-card.ts @@ -82,10 +82,7 @@ export class NumberCard extends MushroomBaseCard<NumberCardConfig> implements Lo updateValue() { this.value = undefined; - if (!this._config || !this.hass || !this._config.entity) return; - - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as HassEntity | undefined; + const stateObj =this._stateObj; if (!stateObj || Number.isNaN(stateObj.state)) return; this.value = Number(stateObj.state); @@ -96,8 +93,7 @@ export class NumberCard extends MushroomBaseCard<NumberCardConfig> implements Lo return nothing; } - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as HassEntity | undefined; + const stateObj = this._stateObj; if (!stateObj) { return this.renderNotFound(this._config);