From 36710d758843a7a861c5957cd0b0371d17296cf9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Jan 2023 10:07:45 -1000 Subject: [PATCH] redraw --- .../lovelace/cards/hui-history-graph-card.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/cards/hui-history-graph-card.ts b/src/panels/lovelace/cards/hui-history-graph-card.ts index 9c30190ce0..f2efb1909b 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.ts +++ b/src/panels/lovelace/cards/hui-history-graph-card.ts @@ -50,6 +50,8 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { private _error?: string; + private _interval?: number; + private _subscribed?: Promise<(() => Promise) | void>; public getCardSize(): number { @@ -97,7 +99,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { private _subscribeHistoryWindow() { if (this._subscribed) { - return true; + return; } this._subscribed = subscribeHistoryStatesWindow( this.hass!, @@ -118,13 +120,26 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { this._subscribed = undefined; this._error = err; }); - return true; + this._setRedrawTimer(); + } + + private _redrawGraph() { + if (this._stateHistory) { + this._stateHistory = { ...this._stateHistory }; + } + } + + private _setRedrawTimer() { + // redraw the graph every minute to update the time axis + clearInterval(this._interval); + this._interval = window.setInterval(() => this._redrawGraph(), 1000 * 60); } private _unsubscribeHistoryWindow() { if (!this._subscribed) { return; } + clearInterval(this._interval); this._subscribed.then((unsubscribe) => { if (unsubscribe) { unsubscribe();