From cae20b70cfc7608086598578fb99c9ef4ad62bef Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Tue, 1 Sep 2020 15:40:09 +0200 Subject: [PATCH] Add service to set cover position with low speed (#242) --- custom_components/tahoma/cover.py | 41 ++++++++++++++++++++++++-- custom_components/tahoma/light.py | 9 ++++-- custom_components/tahoma/services.yaml | 24 ++++++++++----- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/custom_components/tahoma/cover.py b/custom_components/tahoma/cover.py index 33759ebc8..06ab5d3c5 100644 --- a/custom_components/tahoma/cover.py +++ b/custom_components/tahoma/cover.py @@ -1,6 +1,8 @@ """Support for TaHoma cover - shutters etc.""" import logging +import voluptuous as vol + from homeassistant.components.cover import ( ATTR_POSITION, ATTR_TILT_POSITION, @@ -40,6 +42,7 @@ COMMAND_SET_ORIENTATION = "setOrientation" COMMAND_SET_PEDESTRIAN_POSITION = "setPedestrianPosition" COMMAND_SET_POSITION = "setPosition" +COMMAND_SET_POSITION_AND_LINEAR_SPEED = "setPositionAndLinearSpeed" COMMAND_STOP = "stop" COMMAND_STOP_IDENTIFY = "stopIdentify" COMMAND_UP = "up" @@ -66,7 +69,12 @@ STATE_CLOSED = "closed" -SERVICE_MY = "cover_my" +SERVICE_COVER_MY_POSITION = "set_cover_my_position" +SERVICE_COVER_POSITION_LOW_SPEED = "set_cover_position_low_speed" + +SUPPORT_MY = 512 +SUPPORT_COVER_POSITION_LOW_SPEED = 1024 + TAHOMA_COVER_DEVICE_CLASSES = { "Awning": DEVICE_CLASS_AWNING, @@ -100,7 +108,18 @@ async def async_setup_entry(hass, entry, async_add_entities): platform = entity_platform.current_platform.get() platform.async_register_entity_service( - SERVICE_MY, {}, "async_my", + SERVICE_COVER_MY_POSITION, {}, "async_my", [SUPPORT_MY] + ) + + platform.async_register_entity_service( + SERVICE_COVER_POSITION_LOW_SPEED, + { + vol.Required(ATTR_POSITION): vol.All( + vol.Coerce(int), vol.Range(min=0, max=100) + ) + }, + "async_set_cover_position_low_speed", + [SUPPORT_COVER_POSITION_LOW_SPEED], ) @@ -153,6 +172,18 @@ async def async_set_cover_position(self, **kwargs): ) await self.async_execute_command(command, position) + async def async_set_cover_position_low_speed(self, **kwargs): + """Move the cover to a specific position with a low speed.""" + position = 100 - kwargs.get(ATTR_POSITION, 0) + + # HorizontalAwning devices need a reversed position that can not be obtained via the API + if "Horizontal" in self.device.widget: + position = kwargs.get(ATTR_POSITION, 0) + + await self.async_execute_command( + COMMAND_SET_POSITION_AND_LINEAR_SPEED, position, "lowspeed" + ) + async def async_set_cover_tilt_position(self, **kwargs): """Move the cover tilt to a specific position.""" await self.async_execute_command( @@ -292,4 +323,10 @@ def supported_features(self): if self.has_command(COMMAND_CLOSE, COMMAND_DOWN, COMMAND_CYCLE): supported_features |= SUPPORT_CLOSE + if self.has_command(COMMAND_SET_POSITION_AND_LINEAR_SPEED): + supported_features |= SUPPORT_COVER_POSITION_LOW_SPEED + + if self.has_command(COMMAND_MY): + supported_features |= SUPPORT_MY + return supported_features diff --git a/custom_components/tahoma/light.py b/custom_components/tahoma/light.py index bc871f89b..393d2bac9 100644 --- a/custom_components/tahoma/light.py +++ b/custom_components/tahoma/light.py @@ -30,7 +30,9 @@ CORE_LIGHT_INTENSITY_STATE = "core:LightIntensityState" CORE_RED_COLOR_INTENSITY_STATE = "core:RedColorIntensityState" -SERVICE_MY = "light_my" +SERVICE_LIGHT_MY_POSITION = "set_light_my_position" + +SUPPORT_MY = 512 async def async_setup_entry(hass, entry, async_add_entities): @@ -48,7 +50,7 @@ async def async_setup_entry(hass, entry, async_add_entities): platform = entity_platform.current_platform.get() platform.async_register_entity_service( - SERVICE_MY, {}, "async_my", + SERVICE_LIGHT_MY_POSITION, {}, "async_my", [SUPPORT_MY] ) @@ -93,6 +95,9 @@ def supported_features(self) -> int: if self.has_command(COMMAND_SET_RGB): supported_features |= SUPPORT_COLOR + if self.has_command(COMMAND_MY): + supported_features |= SUPPORT_MY + return supported_features async def async_turn_on(self, **kwargs) -> None: diff --git a/custom_components/tahoma/services.yaml b/custom_components/tahoma/services.yaml index 3381fd60f..363264ccd 100644 --- a/custom_components/tahoma/services.yaml +++ b/custom_components/tahoma/services.yaml @@ -1,13 +1,23 @@ -cover_my: - description: Move cover to preset position, simulating the "my" button. +set_cover_my_position: + description: Move to preset position, simulating the "my" button. fields: entity_id: - description: Name of entity that will be set to preset position. + description: Name(s) of cover(s) that will be set to preset position. example: "cover.living_room" -light_my: - description: Move light to preset position, simulating the "my" button. +set_light_my_position: + description: Move to preset position, simulating the "my" button. fields: entity_id: - description: Name of entity that will be set to preset position. - example: "light.living_room" \ No newline at end of file + description: Name(s) of lights that will be set to preset position. + example: "light.living_room" + +set_cover_position_low_speed: + description: Move to specific position all or specified cover with a low speed. + fields: + entity_id: + description: Name(s) of cover(s) to set cover position with a low speed. + example: "cover.living_room" + position: + description: Position of the cover (0 to 100). + example: 30 \ No newline at end of file