Skip to content

Commit

Permalink
Save extra subscribe call.
Browse files Browse the repository at this point in the history
We only need to subscribe `_async_set_available()` callback if field is not yet present in the dataset.
  • Loading branch information
denpamusic committed Aug 1, 2024
1 parent 6aa80a3 commit 7c186fe
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/plum_ecomax/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ async def _async_set_available(value: Any = None) -> None:
self._attr_available = True

if description.key in self.device.data:
await _async_set_available()
await handler(self.device.get_nowait(description.key, None))
value = self.device.get_nowait(description.key, None)
await _async_set_available(value)
await handler(value)
else:
self.device.subscribe_once(description.key, _async_set_available)

self.device.subscribe_once(description.key, _async_set_available)
self.device.subscribe(description.key, handler)

async def async_will_remove_from_hass(self) -> None:
Expand Down

0 comments on commit 7c186fe

Please sign in to comment.