diff --git a/homeassistant/components/velux/cover.py b/homeassistant/components/velux/cover.py index ca529d4c572d24..5a25609119f4cf 100644 --- a/homeassistant/components/velux/cover.py +++ b/homeassistant/components/velux/cover.py @@ -1,7 +1,10 @@ """Support for Velux covers.""" from __future__ import annotations +from datetime import timedelta + from pyvlx import OpeningDevice, Position +from pyvlx.exception import PyVLXException from pyvlx.opening_device import Awning, Blind, GarageDoor, Gate, RollerShutter, Window from homeassistant.components.cover import ( @@ -24,6 +27,9 @@ from . import DATA_VELUX, VeluxEntity +SCAN_INTERVAL = timedelta(seconds=5 * 60) +PARALLEL_UPDATES = 1 + async def async_setup_platform( hass: HomeAssistant, @@ -35,8 +41,12 @@ async def async_setup_platform( entities = [] for node in hass.data[DATA_VELUX].pyvlx.nodes: if isinstance(node, OpeningDevice): - entities.append(VeluxCover(node)) - async_add_entities(entities) + pyvlx_obj = VeluxCover + if isinstance(node, Window): + pyvlx_obj = VeluxWindow + entities.append(pyvlx_obj(node)) + + async_add_entities(entities, True) class VeluxCover(VeluxEntity, CoverEntity): @@ -131,3 +141,38 @@ async def async_set_cover_tilt_position(self, **kwargs): await self.node.set_orientation( orientation=orientation, wait_for_completion=False ) + + +class VeluxWindow(VeluxCover): + def __init__(self, node): + super().__init__(node) + self._extra_attr_limitation_min = None + self._extra_attr_limitation_max = None + + async def async_update(self): + """Get the updated status of the cover. (limitations only)""" + + # TODO: Remove debug code + print("Update", self.name) + + # TODO: handle pyvlx.exception.PyVLXException correctly + try: + limitation = await self.node.get_limitation() + self._extra_attr_limitation_min = limitation.min_value + self._extra_attr_limitation_max = limitation.max_value + except PyVLXException as e: + print("Error fetch limitation", e) + + # TODO: Remove debug code + print("Update", self.name, "finished") + + @property + def should_poll(self): + return True + + @property + def extra_state_attributes(self): + return { + "limitation_min": self._extra_attr_limitation_min, + "limitation_max": self._extra_attr_limitation_max, + } diff --git a/homeassistant/components/velux/manifest.json b/homeassistant/components/velux/manifest.json index c72e25d42eb7cc..4c66a42c4abc6e 100644 --- a/homeassistant/components/velux/manifest.json +++ b/homeassistant/components/velux/manifest.json @@ -2,7 +2,7 @@ "domain": "velux", "name": "Velux", "documentation": "https://www.home-assistant.io/integrations/velux", - "requirements": ["pyvlx==0.2.19"], + "requirements": ["pyvlx==0.2.20"], "codeowners": ["@Julius2342"], "iot_class": "local_polling" } diff --git a/requirements_all.txt b/requirements_all.txt index b38468218e2bef..fca9d00df1a6b0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2036,7 +2036,7 @@ pyvesync==1.4.2 pyvizio==0.1.57 # homeassistant.components.velux -pyvlx==0.2.19 +pyvlx==0.2.20 # homeassistant.components.volumio pyvolumio==0.1.3