From a03589f911329e730c29518f349640467127964b Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Tue, 12 Oct 2021 20:15:34 +0000 Subject: [PATCH 1/5] Add support for pedestrian position --- custom_components/tahoma/__init__.py | 4 +- custom_components/tahoma/select.py | 72 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 custom_components/tahoma/select.py diff --git a/custom_components/tahoma/__init__.py b/custom_components/tahoma/__init__.py index ffc1d0ff1..d87d7f22a 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 @@ -204,7 +205,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Sensor and Binary Sensor will be added dynamically, based on the device states # 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) - supported_platforms.update((BINARY_SENSOR, SENSOR, SWITCH, NUMBER)) + # Select is used at least for DiscreteGateWithPedestrianPosition + supported_platforms.update((BINARY_SENSOR, SENSOR, SWITCH, NUMBER, SELECT)) for platform in supported_platforms: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, platform) diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py new file mode 100644 index 000000000..abda782d1 --- /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_PESTRIAN_POSITION = "setPedestrianPosition" + +OPTION_TO_COMMAND = { + "closed": COMMAND_CLOSE, + "open": COMMAND_OPEN, + "pedestrian": COMMAND_SET_PESTRIAN_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} State" + + @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", "unknown"] + + async def async_select_option(self, option: str) -> None: + """Change the selected option.""" + if option in OPTION_TO_COMMAND: + self.executor.async_execute_command(OPTION_TO_COMMAND[option]) From fbf77e0955d3cd750f2c09a22fa6b74f2e0e2ef1 Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Wed, 13 Oct 2021 06:39:25 +0000 Subject: [PATCH 2/5] Fix missing await --- custom_components/tahoma/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py index abda782d1..ed74f6504 100644 --- a/custom_components/tahoma/select.py +++ b/custom_components/tahoma/select.py @@ -69,4 +69,4 @@ def options(self): async def async_select_option(self, option: str) -> None: """Change the selected option.""" if option in OPTION_TO_COMMAND: - self.executor.async_execute_command(OPTION_TO_COMMAND[option]) + await self.executor.async_execute_command(OPTION_TO_COMMAND[option]) From 990e0239dc252f504165e6360bbbff0d512aaac5 Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Wed, 13 Oct 2021 06:39:49 +0000 Subject: [PATCH 3/5] Update select name --- custom_components/tahoma/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py index ed74f6504..344132201 100644 --- a/custom_components/tahoma/select.py +++ b/custom_components/tahoma/select.py @@ -54,7 +54,7 @@ def __init__( ): """Initialize the device.""" super().__init__(device_url, coordinator) - self._attr_name = f"{super().name} State" + self._attr_name = f"{super().name} Position" @property def current_option(self): From 2ce64bb66e74462124e2c63c18bf203bb1980fd3 Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Wed, 13 Oct 2021 06:43:30 +0000 Subject: [PATCH 4/5] Fix typo --- custom_components/tahoma/select.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py index 344132201..29fb474c4 100644 --- a/custom_components/tahoma/select.py +++ b/custom_components/tahoma/select.py @@ -15,12 +15,12 @@ from .entity import OverkizEntity CORE_OPEN_CLOSED_PEDESTRIAN_STATE = "core:OpenClosedPedestrianState" -COMMAND_SET_PESTRIAN_POSITION = "setPedestrianPosition" +COMMAND_SET_PEDESTRIAN_POSITION = "setPedestrianPosition" OPTION_TO_COMMAND = { "closed": COMMAND_CLOSE, "open": COMMAND_OPEN, - "pedestrian": COMMAND_SET_PESTRIAN_POSITION, + "pedestrian": COMMAND_SET_PEDESTRIAN_POSITION, } From 0aee1fd487c2322d6ace8ef5ac9222721396b20f Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Sat, 16 Oct 2021 22:35:50 +0200 Subject: [PATCH 5/5] Update select.py --- custom_components/tahoma/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/tahoma/select.py b/custom_components/tahoma/select.py index 29fb474c4..8eb887961 100644 --- a/custom_components/tahoma/select.py +++ b/custom_components/tahoma/select.py @@ -64,7 +64,7 @@ def current_option(self): @property def options(self): """Return a set of selectable options.""" - return ["closed", "open", "pedestrian", "unknown"] + return ["closed", "open", "pedestrian"] async def async_select_option(self, option: str) -> None: """Change the selected option."""