From bbc8e323e85b4ae30bf936dc8f1044181918da2a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 1 Feb 2022 18:02:43 +0100 Subject: [PATCH] Add start point to device energy graph (#11507) --- .../cards/energy/hui-energy-devices-graph-card.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts index f59a52e941..df4cd50974 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-devices-graph-card.ts @@ -170,6 +170,21 @@ export class HuiEnergyDevicesGraphCard dayDifference > 35 ? "month" : dayDifference > 2 ? "day" : "hour" ); + const startMinHour = addHours(energyData.start, -1); + + Object.values(this._data).forEach((stat) => { + // if the start of the first value is after the requested period, we have the first data point, and should add a zero point + if (stat.length && new Date(stat[0].start) > startMinHour) { + stat.unshift({ + ...stat[0], + start: startMinHour.toISOString(), + end: startMinHour.toISOString(), + sum: 0, + state: 0, + }); + } + }); + const data: Array>["data"]> = []; const borderColor: string[] = []; const backgroundColor: string[] = [];