Skip to content

Commit

Permalink
Merge pull request #37 from KTibow/patch-1
Browse files Browse the repository at this point in the history
Fixes the bug where HA breaks when entity's not defined
  • Loading branch information
Rocka84 committed May 9, 2021
2 parents 5b8c57d + a538fa4 commit 2a33450
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dual-gauge-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ class DualGaugeCard extends HTMLElement {
}

_update() {
if (this._hass.states[this.config['inner'].entity] == undefined ||
this._hass.states[this.config['outer'].entity] == undefined) {
console.warn("Undefined entity");
if (this.card) {
this.card.remove();
}

this.card = document.createElement('ha-card');
if (this.config.header) {
this.card.header = this.config.header;
}

const content = document.createElement('p');
content.style.background = "#e8e87a";
content.style.padding = "8px";
content.innerHTML = "Error finding these entities:<br>- " +
this.config['inner'].entity +
"<br>- " + this.config['outer'].entity;
this.card.appendChild(content);

this.appendChild(this.card);
return;
} else if (this.card && this.card.firstElementChild.tagName.toLowerCase() == "p") {
this._createCard();
}
this._updateGauge('inner');
this._updateGauge('outer');
}
Expand Down

0 comments on commit 2a33450

Please sign in to comment.