mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Fix duplicated requests in statistics-graph (#25878)
This commit is contained in:
parent
1a8ff83e2d
commit
73cd1e8e9d
@ -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(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user