Fix Energy-Dashboard unexpected Period Calculation (#23458)

* if not whole month, better use days for the period

* fix Type undefined error

* Update src/data/energy.ts

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>

---------

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
libe.net 2024-12-27 10:35:00 +01:00 committed by GitHub
parent a94460a0c7
commit 2ff0cb58bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -401,7 +401,13 @@ const getEnergyData = async (
const dayDifference = differenceInDays(end || new Date(), start); const dayDifference = differenceInDays(end || new Date(), start);
const period = const period =
dayDifference > 35 ? "month" : dayDifference > 2 ? "day" : "hour"; isFirstDayOfMonth(start) &&
(!end || isLastDayOfMonth(end)) &&
dayDifference > 35
? "month"
: dayDifference > 2
? "day"
: "hour";
const lengthUnit = hass.config.unit_system.length || ""; const lengthUnit = hass.config.unit_system.length || "";
const energyUnits: StatisticsUnitConfiguration = { const energyUnits: StatisticsUnitConfiguration = {