Skip to content

Commit

Permalink
feat: Display warning if sensor doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Jan 22, 2021
1 parent fe05bf6 commit a69df3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ views:
hours_to_show: 0.25
series:
- entity: sensor.humidity
- entity: sensor.random0_100
type: bar
# extend_to_end: true
- type: custom:apexcharts-card
hours_to_show: 0.25
Expand Down
20 changes: 19 additions & 1 deletion src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ChartsCard extends LitElement {
let updated = false;
const queue: string[] = [];
this._config.series.forEach((serie, index) => {
serie.index = index; // Required for filtered views
// serie.index = index; // Required for filtered views
const entityState = (hass && hass.states[serie.entity]) || undefined;
if (entityState && this._entities[index] !== entityState) {
this._entities[index] = entityState;
Expand Down Expand Up @@ -118,6 +118,9 @@ class ChartsCard extends LitElement {

protected render(): TemplateResult {
if (!this._config || !this._hass) return html``;
if (this._config.series.some((_, index) => this._entities[index] === undefined)) {
return this.renderWarnings();
}

return html`
<ha-card>
Expand All @@ -128,6 +131,21 @@ class ChartsCard extends LitElement {
`;
}

renderWarnings() {
return html`
<ha-card>
<hui-warning>
<div style="font-weight: bold;">apexcharts-card</div>
${this._config?.series.map((_, index) =>
!this._entities[index]
? html` <div>Entity not available: ${this._config?.series[index].entity}</div> `
: html``,
)}
</hui-warning>
</ha-card>
`;
}

private async _initialLoad() {
await this.updateComplete;

Expand Down

0 comments on commit a69df3d

Please sign in to comment.