Skip to content

Commit 92611f4

Browse files
authored
Fix water sankey calculation to include total supply from sources (#28191)
1 parent 9bc8962 commit 92611f4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/panels/lovelace/cards/water/hui-water-sankey-card.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,32 @@ class HuiWaterSankeyCard
9898
const nodes: Node[] = [];
9999
const links: Link[] = [];
100100

101-
// Calculate total water consumption from all devices
102-
let totalWaterConsumption = 0;
103-
prefs.device_consumption_water.forEach((device) => {
101+
// Calculate total water consumption from all sources or devices
102+
const totalDownstreamConsumption = prefs.device_consumption_water.reduce(
103+
(total, device) => {
104+
const value =
105+
device.stat_consumption in this._data!.stats
106+
? calculateStatisticSumGrowth(
107+
this._data!.stats[device.stat_consumption]
108+
) || 0
109+
: 0;
110+
return total + value;
111+
},
112+
0
113+
);
114+
const totalSourceSupply = waterSources.reduce((total, source) => {
104115
const value =
105-
device.stat_consumption in this._data!.stats
116+
source.stat_energy_from in this._data!.stats
106117
? calculateStatisticSumGrowth(
107-
this._data!.stats[device.stat_consumption]
118+
this._data!.stats[source.stat_energy_from]
108119
) || 0
109120
: 0;
110-
totalWaterConsumption += value;
111-
});
121+
return total + value;
122+
}, 0);
123+
const totalWaterConsumption = Math.max(
124+
totalDownstreamConsumption,
125+
totalSourceSupply
126+
);
112127

113128
// Create home/consumption node
114129
const homeNode: Node = {

0 commit comments

Comments
 (0)