Show statistics in history card on first load (#24554)

* Show statistics in history card on first load

* unnecessary line
This commit is contained in:
karwosts 2025-03-09 23:36:17 -07:00 committed by GitHub
parent 95a99c7857
commit 07c4296771
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -57,6 +57,8 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
private _subscribed?: Promise<(() => Promise<void>) | undefined>; private _subscribed?: Promise<(() => Promise<void>) | undefined>;
private _stateHistory?: HistoryResult;
public getCardSize(): number { public getCardSize(): number {
return this._config?.title ? 2 : 0 + 2 * (this._entityIds?.length || 1); return this._config?.title ? 2 : 0 + 2 * (this._entityIds?.length || 1);
} }
@ -123,7 +125,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
return; return;
} }
const stateHistory = computeHistory( this._stateHistory = computeHistory(
this.hass!, this.hass!,
combinedHistory, combinedHistory,
this._entityIds, this._entityIds,
@ -132,11 +134,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
this._config?.split_device_classes this._config?.split_device_classes
); );
this._history = mergeHistoryResults( this._mergeHistory();
stateHistory,
this._statisticsHistory,
this._config?.split_device_classes
);
}, },
this._hoursToShow, this._hoursToShow,
this._entityIds this._entityIds
@ -151,6 +149,16 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
this._setRedrawTimer(); this._setRedrawTimer();
} }
private _mergeHistory() {
if (this._stateHistory) {
this._history = mergeHistoryResults(
this._stateHistory,
this._statisticsHistory,
this._config?.split_device_classes
);
}
}
private async _fetchStatistics(sensorNumericDeviceClasses: string[]) { private async _fetchStatistics(sensorNumericDeviceClasses: string[]) {
const now = new Date(); const now = new Date();
const start = new Date(); const start = new Date();
@ -173,6 +181,8 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
sensorNumericDeviceClasses, sensorNumericDeviceClasses,
this._config?.split_device_classes this._config?.split_device_classes
); );
this._mergeHistory();
} }
private _redrawGraph() { private _redrawGraph() {