Skip to content

Commit f45e998

Browse files
committed
Add power sankey to overview
1 parent 15ac59b commit f45e998

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/panels/energy/strategies/energy-overview-view-strategy.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export class EnergyViewStrategy extends ReactiveElement {
1515
_config: LovelaceStrategyConfig,
1616
hass: HomeAssistant
1717
): Promise<LovelaceViewConfig> {
18-
const view: LovelaceViewConfig = { type: "sections", sections: [] };
18+
const view: LovelaceViewConfig = {
19+
type: "sections",
20+
sections: [],
21+
dense_section_placement: true,
22+
max_columns: 2,
23+
};
1924

2025
const collectionKey =
2126
_config.collection_key || DEFAULT_ENERGY_COLLECTION_KEY;
@@ -56,11 +61,25 @@ export class EnergyViewStrategy extends ReactiveElement {
5661
(source.type === "battery" && source.stat_rate) ||
5762
(source.type === "grid" && source.power?.length)
5863
);
64+
const hasPowerDevices = prefs.device_consumption.find(
65+
(device) => device.stat_rate
66+
);
5967

6068
const overviewSection: LovelaceSectionConfig = {
6169
type: "grid",
70+
column_span: 24,
6271
cards: [],
6372
};
73+
if (hasPowerSources && hasPowerDevices) {
74+
overviewSection.cards!.push({
75+
title: hass.localize("ui.panel.energy.cards.power_sankey_title"),
76+
type: "power-sankey",
77+
collection_key: collectionKey,
78+
grid_options: {
79+
columns: 24,
80+
},
81+
});
82+
}
6483
// Only include if we have a grid or battery.
6584
if (hasGrid || hasBattery) {
6685
overviewSection.cards!.push({
@@ -69,7 +88,6 @@ export class EnergyViewStrategy extends ReactiveElement {
6988
collection_key: collectionKey,
7089
});
7190
}
72-
7391
if (hasGrid || hasSolar || hasBattery || hasGas || hasWater) {
7492
overviewSection.cards!.push({
7593
type: "energy-sources-table",
@@ -78,7 +96,7 @@ export class EnergyViewStrategy extends ReactiveElement {
7896
}
7997
view.sections!.push(overviewSection);
8098

81-
const energySection: LovelaceSectionConfig = {
99+
const electricitySection: LovelaceSectionConfig = {
82100
type: "grid",
83101
cards: [
84102
{
@@ -93,13 +111,13 @@ export class EnergyViewStrategy extends ReactiveElement {
93111
};
94112

95113
if (hasPowerSources) {
96-
energySection.cards!.push({
114+
electricitySection.cards!.push({
97115
type: "power-sources-graph",
98116
collection_key: collectionKey,
99117
});
100118
}
101119
if (prefs!.device_consumption.length > 3) {
102-
energySection.cards!.push({
120+
electricitySection.cards!.push({
103121
title: hass.localize(
104122
"ui.panel.energy.cards.energy_top_consumers_title"
105123
),
@@ -108,8 +126,7 @@ export class EnergyViewStrategy extends ReactiveElement {
108126
max_devices: 3,
109127
modes: ["bar"],
110128
});
111-
}
112-
if (hasGrid) {
129+
} else if (hasGrid) {
113130
const gauges: LovelaceCardConfig[] = [];
114131
// Only include if we have a grid source & return.
115132
if (hasReturn) {
@@ -142,15 +159,15 @@ export class EnergyViewStrategy extends ReactiveElement {
142159
});
143160
}
144161

145-
energySection.cards!.push({
162+
electricitySection.cards!.push({
146163
type: "grid",
147164
columns: 2,
148165
square: false,
149166
cards: gauges,
150167
});
151168
}
152169

153-
view.sections!.push(energySection);
170+
view.sections!.push(electricitySection);
154171

155172
if (hasGas) {
156173
view.sections!.push({

0 commit comments

Comments
 (0)