From bd5b2e876dfa7186ca49ca277553b12e96cf0c32 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Thu, 11 Jul 2024 14:28:54 -0600 Subject: [PATCH] Handle options update in select entity --- custom_components/oasis_mini/select.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/custom_components/oasis_mini/select.py b/custom_components/oasis_mini/select.py index bb7891a..27ef757 100644 --- a/custom_components/oasis_mini/select.py +++ b/custom_components/oasis_mini/select.py @@ -27,15 +27,7 @@ class OasisMiniSelectEntity(OasisMiniEntity, SelectEntity): ) -> None: """Construct an Oasis Mini select entity.""" super().__init__(coordinator, entry, description) - self._attr_options = [ - TRACKS.get(str(track), {}).get("name", str(track)) - for track in self.device.playlist - ] - - @property - def current_option(self) -> str: - """Return the selected entity option to represent the entity state.""" - return self.options[self.device.playlist_index] + self._handle_coordinator_update() async def async_select_option(self, option: str) -> None: """Change the selected option.""" @@ -44,11 +36,14 @@ class OasisMiniSelectEntity(OasisMiniEntity, SelectEntity): def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - self._attr_options = [ + options = [ TRACKS.get(str(track), {}).get("name", str(track)) for track in self.device.playlist ] - return super()._handle_coordinator_update() + self._attr_options = options + self._attr_current_option = options[self.device.playlist_index] + if self.hass: + return super()._handle_coordinator_update() DESCRIPTOR = SelectEntityDescription(key="playlist", name="Playlist")