Fix period boundaries in Energy dashboard (#25728)

This commit is contained in:
Petar Petrov 2025-06-10 11:28:51 +03:00 committed by Paul Bottein
parent 89ce6870f6
commit 8149ee60cb
No known key found for this signature in database
3 changed files with 11 additions and 10 deletions

View File

@ -679,7 +679,9 @@ export const getEnergyDataCollection = (
const period =
preferredPeriod === "today" && hour === "0" ? "yesterday" : preferredPeriod;
[collection.start, collection.end] = calcDateRange(hass, period);
const [start, end] = calcDateRange(hass, period);
collection.start = calcDate(start, startOfDay, hass.locale, hass.config);
collection.end = calcDate(end, endOfDay, hass.locale, hass.config);
const scheduleUpdatePeriod = () => {
collection._updatePeriodTimeout = window.setTimeout(

View File

@ -10,6 +10,8 @@ import {
addYears,
addMonths,
addHours,
startOfDay,
addDays,
} from "date-fns";
import type {
BarSeriesOption,
@ -282,6 +284,10 @@ export function getCompareTransform(start: Date, compareStart?: Date) {
) {
return (ts: Date) => addMonths(ts, compareMonthDiff);
}
const compareDayDiff = differenceInDays(start, compareStart);
if (compareDayDiff !== 0 && start.getTime() === startOfDay(start).getTime()) {
return (ts: Date) => addDays(ts, compareDayDiff);
}
const compareOffset = start.getTime() - compareStart.getTime();
return (ts: Date) => addMilliseconds(ts, compareOffset);
}

View File

@ -297,24 +297,17 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
}
private _dateRangeChanged(ev) {
const weekStartsOn = firstWeekdayIndex(this.hass.locale);
this._startDate = calcDate(
ev.detail.value.startDate,
startOfDay,
this.hass.locale,
this.hass.config,
{
weekStartsOn,
}
this.hass.config
);
this._endDate = calcDate(
ev.detail.value.endDate,
endOfDay,
this.hass.locale,
this.hass.config,
{
weekStartsOn,
}
this.hass.config
);
this._updateCollectionPeriod();