Skip to content

Commit

Permalink
fix: display a warning if entity is not available (#545)
Browse files Browse the repository at this point in the history
Fixes #487
  • Loading branch information
RomRider authored and jlsjonas committed Jan 22, 2022
1 parent 84178aa commit a334b84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Expand Up @@ -53,3 +53,8 @@ views:
color: "#ff9900"
- value: 500
color: "#ff0000"
- type: custom:mini-graph-card
entities:
- sensor.non_existant
- sensor.random_0_1000
- sensor.non_existant_2
23 changes: 21 additions & 2 deletions src/main.js
Expand Up @@ -145,10 +145,10 @@ class MiniGraphCard extends LitElement {
}

shouldUpdate(changedProps) {
if (!this.entity[0]) return false;
if (UPDATE_PROPS.some(prop => changedProps.has(prop))) {
this.color = this.intColor(
this.tooltip.value !== undefined ? this.tooltip.value : this.entity[0].state,
this.tooltip.value !== undefined
? this.tooltip.value : this.entity[0] && this.entity[0].state,
this.tooltip.entity || 0,
);
return true;
Expand All @@ -173,6 +173,11 @@ class MiniGraphCard extends LitElement {
}

render({ config } = this) {
if (!config || !this.entity || !this._hass)
return html``;
if (this.config.entities.some((_, index) => this.entity[index] === undefined)) {
return this.renderWarnings();
}
return html`
<ha-card
class="flex"
Expand All @@ -191,6 +196,20 @@ class MiniGraphCard extends LitElement {
`;
}

renderWarnings() {
return html`
<hui-warning>
<div>mini-graph-card</div>
${this.config.entities.map((_, index) => (!this.entity[index] ? html`
<div>
Entity not available: ${this.config.entities[index].entity}
</div>
` : html``))}
</hui-warning>
`;
}


renderHeader() {
const {
show, align_icon, align_header, font_size_header,
Expand Down

0 comments on commit a334b84

Please sign in to comment.