Skip to content

Commit 552004b

Browse files
committed
feat(#188): use new energy display names for autoconfig
1 parent b40824c commit 552004b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/energy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface EnergySource {
7373
// eslint-disable-next-line @typescript-eslint/no-empty-interface
7474
export interface DeviceConsumptionEnergyPreference {
7575
stat_consumption: string;
76+
name?: string;
7677
}
7778

7879
export interface EnergyPreferences {

src/ha-sankey-chart.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,19 @@ class SankeyChart extends SubscribeMixin(LitElement) {
197197
}
198198
return 1;
199199
});
200+
const names: Record<string, string> = {};
200201
const deviceIds = (collection.prefs?.device_consumption || [])
201-
.map(d => d.stat_consumption)
202-
.filter(id => {
203-
if (!this.hass.states[id]) {
204-
console.warn('Ignoring missing entity ' + id);
202+
.filter(d => {
203+
if (!this.hass.states[d.stat_consumption]) {
204+
console.warn('Ignoring missing entity ' + d.stat_consumption);
205205
return false;
206206
}
207+
if (d.name) {
208+
names[d.stat_consumption] = d.name;
209+
}
207210
return true;
208-
});
211+
})
212+
.map(d => d.stat_consumption);
209213
const areasResult = await getEntitiesByArea(this.hass, deviceIds);
210214
const areas = Object.values(areasResult)
211215
// put 'No area' last
@@ -260,6 +264,7 @@ class SankeyChart extends SubscribeMixin(LitElement) {
260264
entities: orderedDeviceIds.map(id => ({
261265
entity_id: id,
262266
type: 'entity',
267+
name: names[id],
263268
children: [],
264269
})),
265270
},

0 commit comments

Comments
 (0)