From a76386b53b652e097e71f856149a0b6a12d96249 Mon Sep 17 00:00:00 2001 From: Jerad Meisner Date: Thu, 4 Oct 2018 00:44:01 -0700 Subject: [PATCH] Fix console errors in LL when entities are unavailable. (#1734) --- .../lovelace/entity-rows/hui-input-number-entity-row.js | 4 +++- src/panels/lovelace/entity-rows/hui-input-text-entity-row.js | 2 +- .../lovelace/entity-rows/hui-media-player-entity-row.js | 2 ++ src/panels/lovelace/entity-rows/hui-text-entity-row.js | 2 +- src/panels/lovelace/entity-rows/hui-timer-entity-row.js | 2 ++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/panels/lovelace/entity-rows/hui-input-number-entity-row.js b/src/panels/lovelace/entity-rows/hui-input-number-entity-row.js index 3b4d354cad5c..b756ad7704f3 100644 --- a/src/panels/lovelace/entity-rows/hui-input-number-entity-row.js +++ b/src/panels/lovelace/entity-rows/hui-input-number-entity-row.js @@ -125,7 +125,7 @@ class HuiInputNumberEntityRow extends mixinBehaviors([IronResizableBehavior], Po } _hiddenState() { - if (!this.$ || this._stateObj.attributes.mode !== 'slider') return; + if (!this.$ || !this._stateObj || this._stateObj.attributes.mode !== 'slider') return; const width = this.$.input_number_card.offsetWidth; const stateEl = this.shadowRoot.querySelector('.state'); if (!stateEl) return; @@ -133,6 +133,8 @@ class HuiInputNumberEntityRow extends mixinBehaviors([IronResizableBehavior], Po } _stateObjChanged(stateObj, oldStateObj) { + if (!stateObj) return; + this.setProperties({ _min: Number(stateObj.attributes.min), _max: Number(stateObj.attributes.max), diff --git a/src/panels/lovelace/entity-rows/hui-input-text-entity-row.js b/src/panels/lovelace/entity-rows/hui-input-text-entity-row.js index c3f7a6d718f9..1cfb7e7515ef 100644 --- a/src/panels/lovelace/entity-rows/hui-input-text-entity-row.js +++ b/src/panels/lovelace/entity-rows/hui-input-text-entity-row.js @@ -57,7 +57,7 @@ class HuiInputTextEntityRow extends PolymerElement { } _stateObjChanged(stateObj) { - this._value = stateObj.state; + this._value = stateObj && stateObj.state; } _selectedValueChanged() { diff --git a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.js b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.js index 1c1a382cf8f8..8b359025e1a1 100644 --- a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.js +++ b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.js @@ -89,6 +89,8 @@ class HuiMediaPlayerEntityRow extends LocalizeMixin(PolymerElement) { } _computeControlIcon(stateObj) { + if (!stateObj) return null; + if (stateObj.state !== 'playing') { return stateObj.attributes.supported_features & SUPPORTS_PLAY ? 'hass:play' : ''; } diff --git a/src/panels/lovelace/entity-rows/hui-text-entity-row.js b/src/panels/lovelace/entity-rows/hui-text-entity-row.js index 6e6d9565c55d..3db269648ae3 100644 --- a/src/panels/lovelace/entity-rows/hui-text-entity-row.js +++ b/src/panels/lovelace/entity-rows/hui-text-entity-row.js @@ -64,7 +64,7 @@ class HuiTextEntityRow extends LocalizeMixin(PolymerElement) { } _computeState(stateObj) { - return computeStateDisplay(this.localize, stateObj); + return stateObj && computeStateDisplay(this.localize, stateObj); } } customElements.define('hui-text-entity-row', HuiTextEntityRow); diff --git a/src/panels/lovelace/entity-rows/hui-timer-entity-row.js b/src/panels/lovelace/entity-rows/hui-timer-entity-row.js index 943407784596..1856bf825d9d 100644 --- a/src/panels/lovelace/entity-rows/hui-timer-entity-row.js +++ b/src/panels/lovelace/entity-rows/hui-timer-entity-row.js @@ -73,6 +73,8 @@ class HuiTimerEntityRow extends PolymerElement { } _computeDisplay(stateObj, time) { + if (!stateObj) return null; + if (stateObj.state === 'idle' || time === 0) return stateObj.state; let display = secondsToDuration(time);