Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display a warning if entity is not available #545

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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