Skip to content

Commit

Permalink
Reintroduce low speed feature (#763)
Browse files Browse the repository at this point in the history
* Reintroduce Low Speed cover

* Remove low speed switch

* Fix import
  • Loading branch information
tetienne authored Feb 22, 2022
1 parent 7f915ae commit f7c71fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
9 changes: 8 additions & 1 deletion custom_components/tahoma/cover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Support for Overkiz covers - shutters etc."""
from pyoverkiz.enums import UIClass
from pyoverkiz.enums import OverkizCommand, UIClass

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand Down Expand Up @@ -31,4 +31,11 @@ async def async_setup_entry(
if device.ui_class != UIClass.AWNING
]

entities += [
VerticalCover(device.device_url, data.coordinator, low_speed=True)
for device in data.platforms[Platform.COVER]
if device.ui_class != UIClass.AWNING
and OverkizCommand.SET_CLOSURE_AND_LINEAR_SPEED in device.definition.commands
]

async_add_entities(entities)
40 changes: 36 additions & 4 deletions custom_components/tahoma/cover_entities/vertical_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pyoverkiz.enums import OverkizCommand, OverkizState, UIClass, UIWidget

from custom_components.tahoma.coordinator import OverkizDataUpdateCoordinator
from homeassistant.components.cover import (
ATTR_POSITION,
DEVICE_CLASS_AWNING,
Expand Down Expand Up @@ -42,6 +43,19 @@
class VerticalCover(OverkizGenericCover):
"""Representation of an Overkiz vertical cover."""

def __init__(
self,
device_url: str,
coordinator: OverkizDataUpdateCoordinator,
low_speed: bool = False,
):
"""Initialize the device."""
super().__init__(device_url, coordinator)
self.low_speed = low_speed
if self.low_speed:
self._attr_name = f"{self._attr_name} Low Speed"
self._attr_unique_id = f"{self._attr_unique_id}_low_speed"

@property
def supported_features(self) -> int:
"""Flag supported features."""
Expand Down Expand Up @@ -97,15 +111,33 @@ def current_cover_position(self) -> int | None:

async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
position = 100 - kwargs.get(ATTR_POSITION, 0)
await self.executor.async_execute_command(OverkizCommand.SET_CLOSURE, position)
if self.low_speed:
await self.async_set_cover_position_low_speed(**kwargs)
else:
position = 100 - kwargs.get(ATTR_POSITION, 0)
await self.executor.async_execute_command(
OverkizCommand.SET_CLOSURE, position
)

async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
if command := self.executor.select_command(*COMMANDS_OPEN):
if self.low_speed:
await self.async_set_cover_position_low_speed(**{ATTR_POSITION: 100})

elif command := self.executor.select_command(*COMMANDS_OPEN):
await self.executor.async_execute_command(command)

async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
if command := self.executor.select_command(*COMMANDS_CLOSE):
if self.low_speed:
await self.async_set_cover_position_low_speed(**{ATTR_POSITION: 0})
elif command := self.executor.select_command(*COMMANDS_CLOSE):
await self.executor.async_execute_command(command)

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)

await self.executor.async_execute_command(
OverkizCommand.SET_CLOSURE_AND_LINEAR_SPEED, position, "lowspeed"
)

0 comments on commit f7c71fd

Please sign in to comment.