Skip to content

Commit

Permalink
Fix Energy-Dashboard unexpected Period Calculation (#23458)
Browse files Browse the repository at this point in the history
* if not whole month, better use days for the period

* fix Type undefined error

* Update src/data/energy.ts

Co-authored-by: Petar Petrov <[email protected]>

---------

Co-authored-by: Petar Petrov <[email protected]>
  • Loading branch information
boern99 and MindFreeze authored Dec 27, 2024
1 parent a94460a commit 2ff0cb5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/data/energy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,13 @@ const getEnergyData = async (

const dayDifference = differenceInDays(end || new Date(), start);
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 energyUnits: StatisticsUnitConfiguration = {
Expand Down

0 comments on commit 2ff0cb5

Please sign in to comment.