1
mirror of https://github.com/home-assistant/core synced 2024-07-15 09:42:11 +02:00

Add select platform to Vogel's MotionMount integration (#107132)

This commit is contained in:
RJPoelstra 2024-01-07 10:44:28 +01:00 committed by GitHub
parent e4ff51fa9a
commit c833f275d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 0 deletions

View File

@ -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

View File

@ -15,6 +15,7 @@ from .const import DOMAIN, EMPTY_MAC
PLATFORMS: list[Platform] = [
Platform.NUMBER,
Platform.SELECT,
]

View File

@ -3,3 +3,4 @@
DOMAIN = "motionmount"
EMPTY_MAC = "00:00:00:00:00:00"
WALL_PRESET_NAME = "0_wall"

View File

@ -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)

View File

@ -32,6 +32,14 @@
"motionmount_turn": {
"name": "Turn"
}
},
"select": {
"motionmount_preset": {
"name": "Preset",
"state": {
"0_wall": "0: Wall"
}
}
}
}
}