diff --git a/src/panels/lovelace/cards/hui-camera-preview-card.js b/src/panels/lovelace/cards/hui-camera-preview-card.js index c034379a25..501ee74be6 100644 --- a/src/panels/lovelace/cards/hui-camera-preview-card.js +++ b/src/panels/lovelace/cards/hui-camera-preview-card.js @@ -28,12 +28,15 @@ class HuiCameraPreviewCard extends PolymerElement { if (this.lastChild) { this.removeChild(this.lastChild); } + const entityId = config && config.entity; + if (entityId && !(entityId in this.hass.states)) { + return; + } let error = null; let cardConfig; let tag; - const entityId = config && config.entity; if (entityId) { if (computeDomain(entityId) === 'camera') { this._entityId = entityId; @@ -62,11 +65,13 @@ class HuiCameraPreviewCard extends PolymerElement { } _hassChanged(hass) { - if (this.lastChild && this._entityId) { + if (this.lastChild && this._entityId && this._entityId in hass.states) { const element = this.lastChild; const stateObj = hass.states[this._entityId]; element.stateObj = stateObj; element.hass = hass; + } else { + this._configChanged(this.config); } } } diff --git a/src/panels/lovelace/cards/hui-entities-card.js b/src/panels/lovelace/cards/hui-entities-card.js index 8f797c2fcd..e7d4033104 100644 --- a/src/panels/lovelace/cards/hui-entities-card.js +++ b/src/panels/lovelace/cards/hui-entities-card.js @@ -92,6 +92,7 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) { for (let i = 0; i < config.entities.length; i++) { const entityId = config.entities[i]; + if (!(entityId in this.hass.states)) continue; const stateObj = this.hass.states[entityId]; const tag = stateObj ? `state-card-${stateCardType(this.hass, stateObj)}` : 'state-card-display'; const element = document.createElement(tag); diff --git a/src/panels/lovelace/cards/hui-history-graph-card.js b/src/panels/lovelace/cards/hui-history-graph-card.js index af4820fa57..8cec6690e9 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.js +++ b/src/panels/lovelace/cards/hui-history-graph-card.js @@ -28,12 +28,15 @@ class HuiHistoryGraphCard extends PolymerElement { if (this.lastChild) { this.removeChild(this.lastChild); } + const entityId = config && config.entity; + if (entityId && !(entityId in this.hass.states)) { + return; + } let error = null; let cardConfig; let tag; - const entityId = config && config.entity; if (entityId) { if (computeDomain(entityId) === 'history_graph') { this._entityId = entityId; @@ -62,11 +65,13 @@ class HuiHistoryGraphCard extends PolymerElement { } _hassChanged(hass) { - if (this.lastChild && this._entityId) { + if (this.lastChild && this._entityId && this._entityId in hass.states) { const element = this.lastChild; const stateObj = hass.states[this._entityId]; element.stateObj = stateObj; element.hass = hass; + } else { + this._configChanged(this.config); } } } diff --git a/src/panels/lovelace/cards/hui-media-control-card.js b/src/panels/lovelace/cards/hui-media-control-card.js index ffc811c3e6..c1c7c7972e 100644 --- a/src/panels/lovelace/cards/hui-media-control-card.js +++ b/src/panels/lovelace/cards/hui-media-control-card.js @@ -28,12 +28,15 @@ class HuiMediaControlCard extends PolymerElement { if (this.lastChild) { this.removeChild(this.lastChild); } + const entityId = config && config.entity; + if (entityId && !(entityId in this.hass.states)) { + return; + } let error = null; let cardConfig; let tag; - const entityId = config && config.entity; if (entityId) { if (computeDomain(entityId) === 'media_player') { this._entityId = entityId; @@ -62,11 +65,13 @@ class HuiMediaControlCard extends PolymerElement { } _hassChanged(hass) { - if (this.lastChild && this._entityId) { + if (this.lastChild && this._entityId && this._entityId in hass.states) { const element = this.lastChild; const stateObj = hass.states[this._entityId]; element.stateObj = stateObj; element.hass = hass; + } else { + this._configChanged(this.config); } } } diff --git a/src/panels/lovelace/cards/hui-plant-status-card.js b/src/panels/lovelace/cards/hui-plant-status-card.js index 0d9045b454..f03c91c303 100644 --- a/src/panels/lovelace/cards/hui-plant-status-card.js +++ b/src/panels/lovelace/cards/hui-plant-status-card.js @@ -28,12 +28,15 @@ class HuiPlantStatusCard extends PolymerElement { if (this.lastChild) { this.removeChild(this.lastChild); } + const entityId = config && config.entity; + if (entityId && !(entityId in this.hass.states)) { + return; + } let error = null; let cardConfig; let tag; - const entityId = config && config.entity; if (entityId) { if (computeDomain(entityId) === 'plant') { this._entityId = entityId; @@ -62,11 +65,13 @@ class HuiPlantStatusCard extends PolymerElement { } _hassChanged(hass) { - if (this.lastChild && this._entityId) { + if (this.lastChild && this._entityId && this._entityId in hass.states) { const element = this.lastChild; const stateObj = hass.states[this._entityId]; element.stateObj = stateObj; element.hass = hass; + } else { + this._configChanged(this.config); } } } diff --git a/src/panels/lovelace/cards/hui-weather-forecast-card.js b/src/panels/lovelace/cards/hui-weather-forecast-card.js index a27614c3ec..a3ddf4d056 100644 --- a/src/panels/lovelace/cards/hui-weather-forecast-card.js +++ b/src/panels/lovelace/cards/hui-weather-forecast-card.js @@ -28,12 +28,15 @@ class HuiWeatherForecastCard extends PolymerElement { if (this.lastChild) { this.removeChild(this.lastChild); } + const entityId = config && config.entity; + if (entityId && !(entityId in this.hass.states)) { + return; + } let error = null; let cardConfig; let tag; - const entityId = config && config.entity; if (entityId) { if (computeDomain(entityId) === 'weather') { this._entityId = entityId; @@ -62,11 +65,13 @@ class HuiWeatherForecastCard extends PolymerElement { } _hassChanged(hass) { - if (this.lastChild && this._entityId) { + if (this.lastChild && this._entityId && this._entityId in hass.states) { const element = this.lastChild; const stateObj = hass.states[this._entityId]; element.stateObj = stateObj; element.hass = hass; + } else { + this._configChanged(this.config); } } }