Skip to content

Commit 1ea179b

Browse files
committed
fix(#318): find energy collection by prefix instead of fixed key
1 parent 22a9428 commit 1ea179b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/energy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ export interface EnergyCollection extends Collection<EnergyData> {
9999

100100
export const getEnergyDataCollection = (
101101
hass: HomeAssistant,
102-
key = '_energy'
103102
): EnergyCollection | null => {
104-
if ((hass.connection as any)[key]) {
105-
return (hass.connection as any)[key];
103+
if ((hass.connection as any)['_energy']) {
104+
return (hass.connection as any)['_energy'];
105+
}
106+
for (const key of Object.keys(hass.connection)) {
107+
if (key.startsWith('_energy') && typeof (hass.connection as any)[key]?.subscribe === 'function') {
108+
return (hass.connection as any)[key];
109+
}
106110
}
107111
// HA has not initialized the collection yet and we don't want to interfere with that if energy_date_selection is enabled
108112
return null;

0 commit comments

Comments
 (0)