Love: Fix stateObj not in states error (#1322)

* Love: Fix stateObj not in states error

* Add ()

* Make it dynamic
This commit is contained in:
c727 2018-06-22 16:06:30 +02:00 committed by Paulus Schoutsen
parent d5266c1c56
commit 8d5c862908
6 changed files with 36 additions and 10 deletions

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}