Skip to content

Commit

Permalink
feat(#188): use new energy display names for autoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze committed May 15, 2024
1 parent b40824c commit 552004b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/energy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface EnergySource {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeviceConsumptionEnergyPreference {
stat_consumption: string;
name?: string;
}

export interface EnergyPreferences {
Expand Down
15 changes: 10 additions & 5 deletions src/ha-sankey-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,19 @@ class SankeyChart extends SubscribeMixin(LitElement) {
}
return 1;
});
const names: Record<string, string> = {};
const deviceIds = (collection.prefs?.device_consumption || [])
.map(d => d.stat_consumption)
.filter(id => {
if (!this.hass.states[id]) {
console.warn('Ignoring missing entity ' + id);
.filter(d => {
if (!this.hass.states[d.stat_consumption]) {
console.warn('Ignoring missing entity ' + d.stat_consumption);
return false;
}
if (d.name) {
names[d.stat_consumption] = d.name;
}
return true;
});
})
.map(d => d.stat_consumption);
const areasResult = await getEntitiesByArea(this.hass, deviceIds);
const areas = Object.values(areasResult)
// put 'No area' last
Expand Down Expand Up @@ -260,6 +264,7 @@ class SankeyChart extends SubscribeMixin(LitElement) {
entities: orderedDeviceIds.map(id => ({
entity_id: id,
type: 'entity',
name: names[id],
children: [],
})),
},
Expand Down

0 comments on commit 552004b

Please sign in to comment.