From ddf6ca9105062a8591ba1e9ab702abb01e689592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Mon, 1 Feb 2021 20:04:53 +0000 Subject: [PATCH] fix: Sometimes card would stay in warning mode --- src/apexcharts-card.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index 0714b45..4046097 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -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 @@ -186,6 +186,7 @@ class ChartsCard extends LitElement { return; } else if (this._warning) { this._warning = false; + this._reset(); } if (updated) { this._entities = [...this._entities]; @@ -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) { @@ -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 {