diff --git a/custom_components/tahoma/__init__.py b/custom_components/tahoma/__init__.py index 7acfcfa4a..81f4e0240 100644 --- a/custom_components/tahoma/__init__.py +++ b/custom_components/tahoma/__init__.py @@ -8,6 +8,7 @@ from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR from homeassistant.components.number import DOMAIN as NUMBER from homeassistant.components.scene import DOMAIN as SCENE +from homeassistant.components.select import DOMAIN as SELECT from homeassistant.components.sensor import DOMAIN as SENSOR from homeassistant.components.switch import DOMAIN as SWITCH from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry @@ -180,9 +181,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: platforms = defaultdict(list) # Sensor and Binary Sensor will be added dynamically, based on the device states + # Select will be added dynamically, based on device features (e.g. DiscreteGateWithPedestrianPosition) # Switch will be added dynamically, based on device features (e.g. low speed cover switch) # Number will be added dynamically, based on device features (e.g. My position) - default_platforms = [BINARY_SENSOR, SENSOR, SWITCH, NUMBER] + default_platforms = [BINARY_SENSOR, SELECT, SENSOR, SWITCH, NUMBER] for platform in default_platforms: platforms[platform] = [] diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py new file mode 100644 index 000000000..8eb887961 --- /dev/null +++ b/custom_components/tahoma/select.py @@ -0,0 +1,72 @@ +"""Support for Overkiz select devices.""" +from homeassistant.components.cover import DOMAIN as COVER +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 custom_components.tahoma.coordinator import OverkizDataUpdateCoordinator +from custom_components.tahoma.cover_devices.tahoma_cover import ( + COMMAND_CLOSE, + COMMAND_OPEN, +) + +from .const import DOMAIN +from .entity import OverkizEntity + +CORE_OPEN_CLOSED_PEDESTRIAN_STATE = "core:OpenClosedPedestrianState" +COMMAND_SET_PEDESTRIAN_POSITION = "setPedestrianPosition" + +OPTION_TO_COMMAND = { + "closed": COMMAND_CLOSE, + "open": COMMAND_OPEN, + "pedestrian": COMMAND_SET_PEDESTRIAN_POSITION, +} + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +): + """Set up the Overkiz select from a config entry.""" + data = hass.data[DOMAIN][entry.entry_id] + coordinator = data["coordinator"] + + entities = [ + PedestrianGateSelect(device.deviceurl, coordinator) + for device in data["platforms"][COVER] + if CORE_OPEN_CLOSED_PEDESTRIAN_STATE in device.states + ] + + async_add_entities(entities) + + +class PedestrianGateSelect(OverkizEntity, SelectEntity): + """Representation of the various state for a pedestrian gate.""" + + _attr_icon = "mdi:content-save-cog" + + def __init__( + self, + device_url: str, + coordinator: OverkizDataUpdateCoordinator, + ): + """Initialize the device.""" + super().__init__(device_url, coordinator) + self._attr_name = f"{super().name} Position" + + @property + def current_option(self): + """Return the selected entity option to represent the entity state.""" + return self.device.states.get(CORE_OPEN_CLOSED_PEDESTRIAN_STATE).value + + @property + def options(self): + """Return a set of selectable options.""" + return ["closed", "open", "pedestrian"] + + async def async_select_option(self, option: str) -> None: + """Change the selected option.""" + if option in OPTION_TO_COMMAND: + await self.executor.async_execute_command(OPTION_TO_COMMAND[option])