mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Fix period boundaries in Energy dashboard (#25728)
This commit is contained in:
parent
8523ddfd29
commit
7b9683df89
@ -679,7 +679,9 @@ export const getEnergyDataCollection = (
|
|||||||
const period =
|
const period =
|
||||||
preferredPeriod === "today" && hour === "0" ? "yesterday" : preferredPeriod;
|
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 = () => {
|
const scheduleUpdatePeriod = () => {
|
||||||
collection._updatePeriodTimeout = window.setTimeout(
|
collection._updatePeriodTimeout = window.setTimeout(
|
||||||
|
@ -10,6 +10,8 @@ import {
|
|||||||
addYears,
|
addYears,
|
||||||
addMonths,
|
addMonths,
|
||||||
addHours,
|
addHours,
|
||||||
|
startOfDay,
|
||||||
|
addDays,
|
||||||
} from "date-fns";
|
} from "date-fns";
|
||||||
import type {
|
import type {
|
||||||
BarSeriesOption,
|
BarSeriesOption,
|
||||||
@ -282,6 +284,10 @@ export function getCompareTransform(start: Date, compareStart?: Date) {
|
|||||||
) {
|
) {
|
||||||
return (ts: Date) => addMonths(ts, compareMonthDiff);
|
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();
|
const compareOffset = start.getTime() - compareStart.getTime();
|
||||||
return (ts: Date) => addMilliseconds(ts, compareOffset);
|
return (ts: Date) => addMilliseconds(ts, compareOffset);
|
||||||
}
|
}
|
||||||
|
@ -297,24 +297,17 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _dateRangeChanged(ev) {
|
private _dateRangeChanged(ev) {
|
||||||
const weekStartsOn = firstWeekdayIndex(this.hass.locale);
|
|
||||||
this._startDate = calcDate(
|
this._startDate = calcDate(
|
||||||
ev.detail.value.startDate,
|
ev.detail.value.startDate,
|
||||||
startOfDay,
|
startOfDay,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
this.hass.config,
|
this.hass.config
|
||||||
{
|
|
||||||
weekStartsOn,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
this._endDate = calcDate(
|
this._endDate = calcDate(
|
||||||
ev.detail.value.endDate,
|
ev.detail.value.endDate,
|
||||||
endOfDay,
|
endOfDay,
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
this.hass.config,
|
this.hass.config
|
||||||
{
|
|
||||||
weekStartsOn,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this._updateCollectionPeriod();
|
this._updateCollectionPeriod();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user