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