diff --git a/.coveragerc b/.coveragerc index 0724ff803946..664dbb666f35 100644 --- a/.coveragerc +++ b/.coveragerc @@ -764,6 +764,7 @@ omit = homeassistant/components/motionmount/__init__.py homeassistant/components/motionmount/entity.py homeassistant/components/motionmount/number.py + homeassistant/components/motionmount/select.py homeassistant/components/mpd/media_player.py homeassistant/components/mqtt_room/sensor.py homeassistant/components/msteams/notify.py diff --git a/homeassistant/components/motionmount/__init__.py b/homeassistant/components/motionmount/__init__.py index 8baceb104c3a..4285a12a1015 100644 --- a/homeassistant/components/motionmount/__init__.py +++ b/homeassistant/components/motionmount/__init__.py @@ -15,6 +15,7 @@ from .const import DOMAIN, EMPTY_MAC PLATFORMS: list[Platform] = [ Platform.NUMBER, + Platform.SELECT, ] diff --git a/homeassistant/components/motionmount/const.py b/homeassistant/components/motionmount/const.py index 92045193ad64..884904332af5 100644 --- a/homeassistant/components/motionmount/const.py +++ b/homeassistant/components/motionmount/const.py @@ -3,3 +3,4 @@ DOMAIN = "motionmount" EMPTY_MAC = "00:00:00:00:00:00" +WALL_PRESET_NAME = "0_wall" diff --git a/homeassistant/components/motionmount/select.py b/homeassistant/components/motionmount/select.py new file mode 100644 index 000000000000..ef0b1e918aec --- /dev/null +++ b/homeassistant/components/motionmount/select.py @@ -0,0 +1,60 @@ +"""Support for MotionMount numeric control.""" +import motionmount + +from homeassistant.components.select import SelectEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN, WALL_PRESET_NAME +from .entity import MotionMountEntity + + +async def async_setup_entry( + hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback +) -> None: + """Set up Vogel's MotionMount from a config entry.""" + mm = hass.data[DOMAIN][entry.entry_id] + + async_add_entities([MotionMountPresets(mm, entry)], True) + + +class MotionMountPresets(MotionMountEntity, SelectEntity): + """The presets of a MotionMount.""" + + _attr_translation_key = "motionmount_preset" + _attr_current_option: str | None = None + + def __init__( + self, + mm: motionmount.MotionMount, + config_entry: ConfigEntry, + ) -> None: + """Initialize Preset selector.""" + super().__init__(mm, config_entry) + self._attr_unique_id = f"{self._base_unique_id}-preset" + + def _update_options(self, presets: dict[int, str]) -> None: + """Convert presets to select options.""" + options = [WALL_PRESET_NAME] + for index, name in presets.items(): + options.append(f"{index}: {name}") + + self._attr_options = options + + async def async_update(self) -> None: + """Get latest state from MotionMount.""" + presets = await self.mm.get_presets() + self._update_options(presets) + + if self._attr_current_option is None: + self._attr_current_option = self._attr_options[0] + + async def async_select_option(self, option: str) -> None: + """Set the new option.""" + index = int(option[:1]) + await self.mm.go_to_preset(index) + self._attr_current_option = option + + # Perform an update so we detect changes to the presets (changes are not pushed) + self.async_schedule_update_ha_state(True) diff --git a/homeassistant/components/motionmount/strings.json b/homeassistant/components/motionmount/strings.json index 00a409f30583..2a25611433ab 100644 --- a/homeassistant/components/motionmount/strings.json +++ b/homeassistant/components/motionmount/strings.json @@ -32,6 +32,14 @@ "motionmount_turn": { "name": "Turn" } + }, + "select": { + "motionmount_preset": { + "name": "Preset", + "state": { + "0_wall": "0: Wall" + } + } } } }