Fix duplicated requests in statistics-graph (#25878)

This commit is contained in:
Petar Petrov 2025-06-23 12:25:46 +03:00 committed by Bram Kragten
parent 1a8ff83e2d
commit 73cd1e8e9d

View File

@ -97,8 +97,8 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
} }
if (this._config?.energy_date_selection) { if (this._config?.energy_date_selection) {
this._subscribeEnergy(); this._subscribeEnergy();
} else { } else if (this._interval === undefined) {
this._setFetchStatisticsTimer(); this._setFetchStatisticsTimer(true);
} }
} }
@ -213,9 +213,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
changedProps.has("_config") && changedProps.has("_config") &&
oldConfig?.entities !== this._config.entities oldConfig?.entities !== this._config.entities
) { ) {
this._getStatisticsMetaData(this._entities).then(() => { this._setFetchStatisticsTimer(true);
this._setFetchStatisticsTimer();
});
return; return;
} }
@ -230,10 +228,14 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
} }
} }
private _setFetchStatisticsTimer() { private async _setFetchStatisticsTimer(fetchMetadata = false) {
this._getStatistics();
// statistics are created every hour
clearInterval(this._interval); clearInterval(this._interval);
this._interval = 0; // block concurrent calls
if (fetchMetadata) {
await this._getStatisticsMetaData(this._entities);
}
await this._getStatistics();
// statistics are created every hour
if (!this._config?.energy_date_selection) { if (!this._config?.energy_date_selection) {
this._interval = window.setInterval( this._interval = window.setInterval(
() => this._getStatistics(), () => this._getStatistics(),