From 3f03848a07c8cf365deeda20acaebc37fd5b3318 Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Sun, 26 Jan 2020 14:36:29 +0100 Subject: [PATCH] Fix Velbus covers (includes velbus lib upgrade) (#31153) * Fix velbus covers * Update python-velbus lib * flake8 and black fixes * Fix comments * fix codeowner --- CODEOWNERS | 2 +- homeassistant/components/velbus/cover.py | 23 ++++++++++++++----- homeassistant/components/velbus/manifest.json | 4 ++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 49993f5d5ad..0a1f92290d9 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -368,7 +368,7 @@ homeassistant/components/upnp/* @robbiet480 homeassistant/components/uptimerobot/* @ludeeus homeassistant/components/usgs_earthquakes_feed/* @exxamalte homeassistant/components/utility_meter/* @dgomes -homeassistant/components/velbus/* @cereal2nd +homeassistant/components/velbus/* @Cereal2nd homeassistant/components/velux/* @Julius2342 homeassistant/components/versasense/* @flamm3blemuff1n homeassistant/components/version/* @fabaff diff --git a/homeassistant/components/velbus/cover.py b/homeassistant/components/velbus/cover.py index 3e7df39b333..4478bb81c3c 100644 --- a/homeassistant/components/velbus/cover.py +++ b/homeassistant/components/velbus/cover.py @@ -4,8 +4,10 @@ import logging from velbus.util import VelbusException from homeassistant.components.cover import ( + ATTR_POSITION, SUPPORT_CLOSE, SUPPORT_OPEN, + SUPPORT_SET_POSITION, SUPPORT_STOP, CoverDevice, ) @@ -33,24 +35,26 @@ class VelbusCover(VelbusEntity, CoverDevice): @property def supported_features(self): """Flag supported features.""" + if self._module.support_position(): + return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP @property def is_closed(self): """Return if the cover is closed.""" - return self._module.is_closed(self._channel) + if self._module.get_position(self._channel) == 100: + return True + return False @property def current_cover_position(self): """Return current position of cover. None is unknown, 0 is closed, 100 is fully open + Velbus: 100 = closed, 0 = open """ - if self._module.is_closed(self._channel): - return 0 - if self._module.is_open(self._channel): - return 100 - return None + pos = self._module.get_position(self._channel) + return 100 - pos def open_cover(self, **kwargs): """Open the cover.""" @@ -72,3 +76,10 @@ class VelbusCover(VelbusEntity, CoverDevice): self._module.stop(self._channel) except VelbusException as err: _LOGGER.error("A Velbus error occurred: %s", err) + + def set_cover_position(self, **kwargs): + """Move the cover to a specific position.""" + try: + self._module.set(self._channel, (100 - kwargs[ATTR_POSITION])) + except VelbusException as err: + _LOGGER.error("A Velbus error occurred: %s", err) diff --git a/homeassistant/components/velbus/manifest.json b/homeassistant/components/velbus/manifest.json index 250b2c01e4e..548dd0e6356 100644 --- a/homeassistant/components/velbus/manifest.json +++ b/homeassistant/components/velbus/manifest.json @@ -2,8 +2,8 @@ "domain": "velbus", "name": "Velbus", "documentation": "https://www.home-assistant.io/integrations/velbus", - "requirements": ["python-velbus==2.0.35"], + "requirements": ["python-velbus==2.0.36"], "config_flow": true, "dependencies": [], - "codeowners": ["@cereal2nd"] + "codeowners": ["@Cereal2nd"] } diff --git a/requirements_all.txt b/requirements_all.txt index ab4afb72bad..fab2f1c3baa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1629,7 +1629,7 @@ python-telnet-vlc==1.0.4 python-twitch-client==0.6.0 # homeassistant.components.velbus -python-velbus==2.0.35 +python-velbus==2.0.36 # homeassistant.components.vlc python-vlc==1.1.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a3e2f8a03cc..83353008840 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -540,7 +540,7 @@ python-miio==0.4.8 python-nest==4.1.0 # homeassistant.components.velbus -python-velbus==2.0.35 +python-velbus==2.0.36 # homeassistant.components.awair python_awair==0.0.4