Skip to content

Commit

Permalink
Add service to set cover position with low speed (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl authored Sep 1, 2020
1 parent aa92fdc commit cae20b7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
41 changes: 39 additions & 2 deletions custom_components/tahoma/cover.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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],
)


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
9 changes: 7 additions & 2 deletions custom_components/tahoma/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]
)


Expand Down Expand Up @@ -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:
Expand Down
24 changes: 17 additions & 7 deletions custom_components/tahoma/services.yaml
Original file line number Diff line number Diff line change
@@ -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"
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

0 comments on commit cae20b7

Please sign in to comment.