mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Make preset list indicate whether the current mount position matches a preset in Vogel's Motionmount (#118731)
This commit is contained in:
parent
4de8cca911
commit
353e4865e1
@ -24,7 +24,6 @@ class MotionMountPresets(MotionMountEntity, SelectEntity):
|
|||||||
"""The presets of a MotionMount."""
|
"""The presets of a MotionMount."""
|
||||||
|
|
||||||
_attr_translation_key = "motionmount_preset"
|
_attr_translation_key = "motionmount_preset"
|
||||||
_attr_current_option: str | None = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -34,6 +33,7 @@ class MotionMountPresets(MotionMountEntity, SelectEntity):
|
|||||||
"""Initialize Preset selector."""
|
"""Initialize Preset selector."""
|
||||||
super().__init__(mm, config_entry)
|
super().__init__(mm, config_entry)
|
||||||
self._attr_unique_id = f"{self._base_unique_id}-preset"
|
self._attr_unique_id = f"{self._base_unique_id}-preset"
|
||||||
|
self._presets: list[motionmount.Preset] = []
|
||||||
|
|
||||||
def _update_options(self, presets: list[motionmount.Preset]) -> None:
|
def _update_options(self, presets: list[motionmount.Preset]) -> None:
|
||||||
"""Convert presets to select options."""
|
"""Convert presets to select options."""
|
||||||
@ -44,11 +44,30 @@ class MotionMountPresets(MotionMountEntity, SelectEntity):
|
|||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get latest state from MotionMount."""
|
"""Get latest state from MotionMount."""
|
||||||
presets = await self.mm.get_presets()
|
self._presets = await self.mm.get_presets()
|
||||||
self._update_options(presets)
|
self._update_options(self._presets)
|
||||||
|
|
||||||
if self._attr_current_option is None:
|
@property
|
||||||
self._attr_current_option = self._attr_options[0]
|
def current_option(self) -> str | None:
|
||||||
|
"""Get the current option."""
|
||||||
|
# When the mount is moving we return the currently selected option
|
||||||
|
if self.mm.is_moving:
|
||||||
|
return self._attr_current_option
|
||||||
|
|
||||||
|
# When the mount isn't moving we select the option that matches the current position
|
||||||
|
self._attr_current_option = None
|
||||||
|
if self.mm.extension == 0 and self.mm.turn == 0:
|
||||||
|
self._attr_current_option = self._attr_options[0] # Select Wall preset
|
||||||
|
else:
|
||||||
|
for preset in self._presets:
|
||||||
|
if (
|
||||||
|
preset.extension == self.mm.extension
|
||||||
|
and preset.turn == self.mm.turn
|
||||||
|
):
|
||||||
|
self._attr_current_option = f"{preset.index}: {preset.name}"
|
||||||
|
break
|
||||||
|
|
||||||
|
return self._attr_current_option
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Set the new option."""
|
"""Set the new option."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user