Skip to content

Commit

Permalink
fix: Sometimes card would stay in warning mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Feb 1, 2021
1 parent fa418a3 commit ddf6ca9
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/apexcharts-card.ts
Expand Up @@ -172,8 +172,8 @@ class ChartsCard extends LitElement {
let updated = false;
this._config.series.forEach((serie, index) => {
const entityState = (hass && hass.states[serie.entity]) || undefined;
this._entities[index] = entityState;
if (entityState && this._entities[index] !== entityState) {
this._entities[index] = entityState;
updated = true;
if (this._graphs && this._graphs[index]) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -186,6 +186,7 @@ class ChartsCard extends LitElement {
return;
} else if (this._warning) {
this._warning = false;
this._reset();
}
if (updated) {
this._entities = [...this._entities];
Expand All @@ -203,6 +204,19 @@ class ChartsCard extends LitElement {
}
}

private _reset() {
if (this._apexChart) {
this._apexChart.destroy();
this._apexChart = undefined;
this._loaded = false;
this._dataLoaded = false;
this._updating = false;
}
if (this._config && this._hass && !this._loaded) {
this._initialLoad();
}
}

public setConfig(config: ChartCardExternalConfig) {
const configDup = JSON.parse(JSON.stringify(config));
if (configDup.entities) {
Expand Down Expand Up @@ -292,17 +306,8 @@ class ChartsCard extends LitElement {
return undefined;
});
}
// Reset only happens in editor mode
if (this._apexChart) {
this._apexChart.destroy();
this._apexChart = undefined;
this._loaded = false;
this._dataLoaded = false;
this._updating = false;
}
if (this._config && this._hass && !this._loaded) {
this._initialLoad();
}
// Full reset only happens in editor mode
this._reset();
}

static get styles(): CSSResult {
Expand Down

0 comments on commit ddf6ca9

Please sign in to comment.