1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 08:33:31 +01:00

Fix stale data point in history-graph cards with sub-hour windows (#29998)

Skip fetching hourly statistics when hours_to_show < 1 since hourly
aggregates produce stale outlier points in sub-hour chart windows
(e.g. hours_to_show: 0.1 or 0.05).

Also fix Date object handling in ha-chart-base downsampling bounds
extraction.
This commit is contained in:
Petar Petrov
2026-03-06 19:42:52 +01:00
committed by Bram Kragten
parent 1a6d46a7ff
commit 8d42395938
2 changed files with 18 additions and 4 deletions

View File

@@ -877,10 +877,20 @@ export class HaChartBase extends LitElement {
};
}
if (s.sampling === "minmax") {
const minX =
xAxis?.min && typeof xAxis.min === "number" ? xAxis.min : undefined;
const maxX =
xAxis?.max && typeof xAxis.max === "number" ? xAxis.max : undefined;
const minX = xAxis?.min
? xAxis.min instanceof Date
? xAxis.min.getTime()
: typeof xAxis.min === "number"
? xAxis.min
: undefined
: undefined;
const maxX = xAxis?.max
? xAxis.max instanceof Date
? xAxis.max.getTime()
: typeof xAxis.max === "number"
? xAxis.max
: undefined
: undefined;
return {
...s,
sampling: undefined,

View File

@@ -185,6 +185,10 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
}
private async _fetchStatistics(sensorNumericDeviceClasses: string[]) {
if (this._hoursToShow < 1) {
// Statistics are hourly aggregates, not useful for sub-hour windows
return;
}
const now = new Date();
const start = new Date();
start.setHours(start.getHours() - this._hoursToShow - 1);