mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 20:56:36 +00:00
prevent fetching stats twice
This commit is contained in:
parent
e31d1aace0
commit
95bbf6e0d2
@ -38,8 +38,6 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
|
||||
private _names: Record<string, string> = {};
|
||||
|
||||
private _fetching = false;
|
||||
|
||||
private _interval?: number;
|
||||
|
||||
public disconnectedCallback() {
|
||||
@ -156,15 +154,11 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
private async _getStatistics(): Promise<void> {
|
||||
if (this._fetching) {
|
||||
return;
|
||||
}
|
||||
const startDate = new Date();
|
||||
startDate.setTime(
|
||||
startDate.getTime() -
|
||||
1000 * 60 * 60 * (24 * (this._config!.days_to_show || 30) + 1)
|
||||
);
|
||||
this._fetching = true;
|
||||
try {
|
||||
this._statistics = await fetchStatistics(
|
||||
this.hass!,
|
||||
@ -173,8 +167,8 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
this._entities,
|
||||
this._config!.period
|
||||
);
|
||||
} finally {
|
||||
this._fetching = false;
|
||||
} catch (err) {
|
||||
this._statistics = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,12 +94,6 @@ export class HuiStatisticsGraphCardEditor
|
||||
this.hass!,
|
||||
statisticIds || []
|
||||
);
|
||||
if (statisticIds?.some((statistic_id) => statistic_id.includes(":"))) {
|
||||
const { period, ...config } = this._config!;
|
||||
fireEvent(this, "config-changed", {
|
||||
config: config,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
@ -239,8 +233,15 @@ export class HuiStatisticsGraphCardEditor
|
||||
}
|
||||
|
||||
private _entitiesChanged(ev: CustomEvent): void {
|
||||
const config = { ...this._config!, entities: ev.detail.value };
|
||||
if (
|
||||
config.entities?.some((statistic_id) => statistic_id.includes(":")) &&
|
||||
config.period === "5minute"
|
||||
) {
|
||||
delete config.period;
|
||||
}
|
||||
fireEvent(this, "config-changed", {
|
||||
config: { ...this._config!, entities: ev.detail.value },
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user