From c28a7a682b9bb0943fd82a24f525c87801fbe4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Sun, 4 Jul 2021 08:46:49 +0000 Subject: [PATCH] fix: Ignore recorder when not required Fix #169 --- .devcontainer/ui-lovelace.yaml | 3 +++ src/apexcharts-card.ts | 7 +++++++ src/graphEntry.ts | 11 +++++++++++ src/types.ts | 1 + 4 files changed, 22 insertions(+) diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index 9c7d213..1cdeca7 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -440,6 +440,9 @@ views: unit: Mbits/s min: 0 max: 1000 + group_by: + func: max + duration: 30min - type: custom:apexcharts-card chart_type: pie header: diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index 6c6fe72..d41b670 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -384,6 +384,13 @@ class ChartsCard extends LitElement { } this._graphs = this._config.series.map((serie, index) => { serie.index = index; + serie.ignore_history = !!( + this._config?.chart_type && + ['donut', 'pie', 'radialBar'].includes(this._config?.chart_type) && + (!serie.group_by || serie.group_by?.func === 'raw') && + !serie.data_generator && + !serie.offset + ); if (!this._headerColors[index]) { this._headerColors[index] = defColors[index % defColors.length]; } diff --git a/src/graphEntry.ts b/src/graphEntry.ts index e188a4c..aec88bb 100644 --- a/src/graphEntry.ts +++ b/src/graphEntry.ts @@ -183,6 +183,17 @@ export default class GraphEntry { } if (!this._entityState || this._updating) return false; this._updating = true; + + if (this._config.ignore_history) { + let currentState: null | number | string = this._entityState.state; + if (this._config.transform) { + currentState = this._applyTransform(currentState, this._entityState); + } + this._computedHistory = [[new Date(this._entityState.last_updated).getTime(), Number(currentState)]]; + this._updating = false; + return true; + } + let history: EntityEntryCache | undefined = undefined; if (this._config.data_generator) { diff --git a/src/types.ts b/src/types.ts index c74403e..2145f49 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,6 +28,7 @@ export interface ChartCardSeriesConfig extends ChartCardSeriesExternalConfig { start_with_last?: boolean; }; show: ChartCardSeriesShowConfig; + ignore_history: boolean; } export interface ChartCardSeriesShowConfig extends ChartCardSeriesShowConfigExt {