mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Add select platform to Vogel's MotionMount integration (#107132)
This commit is contained in:
parent
e4ff51fa9a
commit
c833f275d6
@ -764,6 +764,7 @@ omit =
|
|||||||
homeassistant/components/motionmount/__init__.py
|
homeassistant/components/motionmount/__init__.py
|
||||||
homeassistant/components/motionmount/entity.py
|
homeassistant/components/motionmount/entity.py
|
||||||
homeassistant/components/motionmount/number.py
|
homeassistant/components/motionmount/number.py
|
||||||
|
homeassistant/components/motionmount/select.py
|
||||||
homeassistant/components/mpd/media_player.py
|
homeassistant/components/mpd/media_player.py
|
||||||
homeassistant/components/mqtt_room/sensor.py
|
homeassistant/components/mqtt_room/sensor.py
|
||||||
homeassistant/components/msteams/notify.py
|
homeassistant/components/msteams/notify.py
|
||||||
|
@ -15,6 +15,7 @@ from .const import DOMAIN, EMPTY_MAC
|
|||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.NUMBER,
|
Platform.NUMBER,
|
||||||
|
Platform.SELECT,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,3 +3,4 @@
|
|||||||
DOMAIN = "motionmount"
|
DOMAIN = "motionmount"
|
||||||
|
|
||||||
EMPTY_MAC = "00:00:00:00:00:00"
|
EMPTY_MAC = "00:00:00:00:00:00"
|
||||||
|
WALL_PRESET_NAME = "0_wall"
|
||||||
|
60
homeassistant/components/motionmount/select.py
Normal file
60
homeassistant/components/motionmount/select.py
Normal 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)
|
@ -32,6 +32,14 @@
|
|||||||
"motionmount_turn": {
|
"motionmount_turn": {
|
||||||
"name": "Turn"
|
"name": "Turn"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"select": {
|
||||||
|
"motionmount_preset": {
|
||||||
|
"name": "Preset",
|
||||||
|
"state": {
|
||||||
|
"0_wall": "0: Wall"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user