@@ -10,6 +10,7 @@ import type { LovelaceViewConfig } from "../../../data/lovelace/config/view";
1010import type { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy" ;
1111import type { LovelaceSectionConfig } from "../../../data/lovelace/config/section" ;
1212import type { LovelaceCardConfig } from "../../../data/lovelace/config/card" ;
13+ import { DEFAULT_ENERGY_COLLECTION_KEY } from "../ha-panel-energy" ;
1314
1415const setupWizard = async ( ) : Promise < LovelaceViewConfig > => {
1516 await import ( "../cards/energy-setup-wizard-card" ) ;
@@ -34,6 +35,8 @@ export class EnergyViewStrategy extends ReactiveElement {
3435 const view : LovelaceViewConfig = { type : "sections" , sections : [ ] } ;
3536
3637 let prefs : EnergyPreferences ;
38+ const collectionKey =
39+ _config . collection_key || DEFAULT_ENERGY_COLLECTION_KEY ;
3740
3841 try {
3942 prefs = await getEnergyPreferences ( hass ) ;
@@ -80,11 +83,10 @@ export class EnergyViewStrategy extends ReactiveElement {
8083
8184 const energySection : LovelaceSectionConfig = {
8285 type : "grid" ,
83- column_span : COLUMNS ,
8486 cards : [
8587 {
8688 type : "heading" ,
87- heading : hass . localize ( "ui.panel.energy.electricity_overview_title " ) ,
89+ heading : hass . localize ( "ui.panel.energy.summary_list.energy " ) ,
8890 tap_action : {
8991 action : "navigate" ,
9092 navigation_path : "/energy/electricity" ,
@@ -98,48 +100,52 @@ export class EnergyViewStrategy extends ReactiveElement {
98100 title : hass . localize ( "ui.panel.energy.cards.energy_distribution_title" ) ,
99101 type : "energy-distribution" ,
100102 view_layout : { position : "sidebar" } ,
101- collection_key : "energy_dashboard" ,
103+ collection_key : collectionKey ,
102104 } ) ;
103105 }
104106
105- const gauges : LovelaceCardConfig [ ] = [ ] ;
106- // Only include if we have a grid source & return.
107- if ( hasReturn ) {
108- gauges . push ( {
109- type : "energy-grid-neutrality-gauge" ,
110- view_layout : { position : "sidebar" } ,
111- collection_key : "energy_dashboard" ,
107+ if ( prefs ! . device_consumption . length > 0 ) {
108+ energySection . cards ! . push ( {
109+ title : hass . localize (
110+ "ui.panel.energy.cards.energy_top_consumers_title"
111+ ) ,
112+ type : "energy-devices-graph" ,
113+ collection_key : collectionKey ,
114+ max_devices : 5 ,
112115 } ) ;
113- }
116+ } else if ( hasGrid ) {
117+ const gauges : LovelaceCardConfig [ ] = [ ] ;
118+ // Only include if we have a grid source & return.
119+ if ( hasReturn ) {
120+ gauges . push ( {
121+ type : "energy-grid-neutrality-gauge" ,
122+ view_layout : { position : "sidebar" } ,
123+ collection_key : collectionKey ,
124+ } ) ;
125+ }
114126
115- // Only include if we have a grid
116- if ( hasGrid ) {
117127 gauges . push ( {
118128 type : "energy-carbon-consumed-gauge" ,
119129 view_layout : { position : "sidebar" } ,
120- collection_key : "energy_dashboard" ,
130+ collection_key : collectionKey ,
121131 } ) ;
122- }
123132
124- // Only include if we have a solar source.
125- if ( hasSolar ) {
126- if ( hasReturn ) {
127- gauges . push ( {
128- type : "energy-solar-consumed-gauge" ,
129- view_layout : { position : "sidebar" } ,
130- collection_key : "energy_dashboard" ,
131- } ) ;
132- }
133- if ( hasGrid ) {
133+ // Only include if we have a solar source.
134+ if ( hasSolar ) {
135+ if ( hasReturn ) {
136+ gauges . push ( {
137+ type : "energy-solar-consumed-gauge" ,
138+ view_layout : { position : "sidebar" } ,
139+ collection_key : collectionKey ,
140+ } ) ;
141+ }
134142 gauges . push ( {
135143 type : "energy-self-sufficiency-gauge" ,
136144 view_layout : { position : "sidebar" } ,
137- collection_key : "energy_dashboard" ,
145+ collection_key : collectionKey ,
138146 } ) ;
139147 }
140- }
141148
142- if ( gauges . length ) {
143149 energySection . cards ! . push ( {
144150 type : "grid" ,
145151 columns : 2 ,
@@ -153,18 +159,55 @@ export class EnergyViewStrategy extends ReactiveElement {
153159 if ( hasGas ) {
154160 view . sections ! . push ( {
155161 type : "grid" ,
156- column_span : 1 ,
157162 cards : [
158163 {
159164 type : "heading" ,
160- heading : hass . localize ( "ui.panel.energy.gas_overview_title" ) ,
161- tap_action : { action : "navigate" , navigation_path : "/energy/gas" } ,
165+ heading : hass . localize ( "ui.panel.energy.summary_list.gas" ) ,
162166 } ,
163167 {
164- title : hass . localize ( "ui.panel.energy.cards.energy_gas_graph_title" ) ,
168+ title : hass . localize (
169+ "ui.panel.energy.cards.energy_gas_graph_title"
170+ ) ,
165171 type : "energy-gas-graph" ,
166- collection_key : "energy_dashboard" ,
167- }
172+ collection_key : collectionKey ,
173+ } ,
174+ ] ,
175+ } ) ;
176+ }
177+
178+ if ( hasWater ) {
179+ view . sections ! . push ( {
180+ type : "grid" ,
181+ cards : [
182+ {
183+ type : "heading" ,
184+ heading : hass . localize ( "ui.panel.energy.summary_list.water" ) ,
185+ } ,
186+ {
187+ title : hass . localize (
188+ "ui.panel.energy.cards.energy_water_graph_title"
189+ ) ,
190+ type : "energy-water-graph" ,
191+ collection_key : collectionKey ,
192+ } ,
193+ ] ,
194+ } ) ;
195+ }
196+
197+ if ( hasGrid || hasSolar || hasBattery || hasGas || hasWater ) {
198+ view . sections ! . push ( {
199+ type : "grid" ,
200+ cards : [
201+ {
202+ type : "heading" ,
203+ heading : hass . localize (
204+ "ui.panel.energy.cards.energy_sources_table_title"
205+ ) ,
206+ } ,
207+ {
208+ type : "energy-sources-table" ,
209+ collection_key : collectionKey ,
210+ } ,
168211 ] ,
169212 } ) ;
170213 }
0 commit comments