mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-29 04:06:35 +00:00
Improve handling of batteries in sankey chart (#25175)
This commit is contained in:
parent
834ece8547
commit
3b0cd9e3ae
@ -123,30 +123,6 @@ class HuiEnergySankeyCard
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add battery source if available
|
|
||||||
if (types.battery) {
|
|
||||||
const totalBatteryOut =
|
|
||||||
calculateStatisticsSumGrowth(
|
|
||||||
this._data.stats,
|
|
||||||
types.battery.map((source) => source.stat_energy_from)
|
|
||||||
) || 0;
|
|
||||||
|
|
||||||
nodes.push({
|
|
||||||
id: "battery",
|
|
||||||
label: this.hass.localize(
|
|
||||||
"ui.panel.lovelace.cards.energy.energy_distribution.battery"
|
|
||||||
),
|
|
||||||
value: totalBatteryOut,
|
|
||||||
tooltip: `${formatNumber(totalBatteryOut, this.hass.locale)} kWh`,
|
|
||||||
color: computedStyle.getPropertyValue("--energy-battery-out-color"),
|
|
||||||
index: 0,
|
|
||||||
});
|
|
||||||
links.push({
|
|
||||||
source: "battery",
|
|
||||||
target: "home",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add solar if available
|
// Add solar if available
|
||||||
if (types.solar) {
|
if (types.solar) {
|
||||||
const totalSolarProduction =
|
const totalSolarProduction =
|
||||||
@ -172,26 +148,51 @@ class HuiEnergySankeyCard
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate total home consumption from all source nodes
|
// Calculate total home consumption from all producers
|
||||||
homeNode.value = nodes
|
homeNode.value = nodes
|
||||||
.filter((node) => node.index === 0)
|
.filter((node) => node.index === 0)
|
||||||
.reduce((sum, node) => sum + (node.value || 0), 0);
|
.reduce((sum, node) => sum + (node.value || 0), 0);
|
||||||
|
|
||||||
// Add battery sink if available
|
|
||||||
if (types.battery) {
|
if (types.battery) {
|
||||||
|
// Add battery source
|
||||||
|
const totalBatteryOut =
|
||||||
|
calculateStatisticsSumGrowth(
|
||||||
|
this._data.stats,
|
||||||
|
types.battery.map((source) => source.stat_energy_from)
|
||||||
|
) || 0;
|
||||||
const totalBatteryIn =
|
const totalBatteryIn =
|
||||||
calculateStatisticsSumGrowth(
|
calculateStatisticsSumGrowth(
|
||||||
this._data.stats,
|
this._data.stats,
|
||||||
types.battery.map((source) => source.stat_energy_to)
|
types.battery.map((source) => source.stat_energy_to)
|
||||||
) || 0;
|
) || 0;
|
||||||
|
const netBattery = totalBatteryOut - totalBatteryIn;
|
||||||
|
const netBatteryOut = Math.max(netBattery, 0);
|
||||||
|
const netBatteryIn = Math.max(-netBattery, 0);
|
||||||
|
homeNode.value += netBattery;
|
||||||
|
|
||||||
|
nodes.push({
|
||||||
|
id: "battery",
|
||||||
|
label: this.hass.localize(
|
||||||
|
"ui.panel.lovelace.cards.energy.energy_distribution.battery"
|
||||||
|
),
|
||||||
|
value: netBatteryOut,
|
||||||
|
tooltip: `${formatNumber(netBatteryOut, this.hass.locale)} kWh`,
|
||||||
|
color: computedStyle.getPropertyValue("--energy-battery-out-color"),
|
||||||
|
index: 0,
|
||||||
|
});
|
||||||
|
links.push({
|
||||||
|
source: "battery",
|
||||||
|
target: "home",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add battery sink
|
||||||
nodes.push({
|
nodes.push({
|
||||||
id: "battery_in",
|
id: "battery_in",
|
||||||
label: this.hass.localize(
|
label: this.hass.localize(
|
||||||
"ui.panel.lovelace.cards.energy.energy_distribution.battery"
|
"ui.panel.lovelace.cards.energy.energy_distribution.battery"
|
||||||
),
|
),
|
||||||
value: totalBatteryIn,
|
value: netBatteryIn,
|
||||||
tooltip: `${formatNumber(totalBatteryIn, this.hass.locale)} kWh`,
|
tooltip: `${formatNumber(netBatteryIn, this.hass.locale)} kWh`,
|
||||||
color: computedStyle.getPropertyValue("--energy-battery-in-color"),
|
color: computedStyle.getPropertyValue("--energy-battery-in-color"),
|
||||||
index: 1,
|
index: 1,
|
||||||
});
|
});
|
||||||
@ -204,8 +205,6 @@ class HuiEnergySankeyCard
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
homeNode.value -= totalBatteryIn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add grid return if available
|
// Add grid return if available
|
||||||
|
Loading…
x
Reference in New Issue
Block a user