Skip to content

Commit

Permalink
First prototype for velux limitation sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Gröbmeyer committed Jan 17, 2022
1 parent d3da791 commit 7e82744
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
49 changes: 47 additions & 2 deletions homeassistant/components/velux/cover.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion homeassistant/components/velux/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e82744

Please sign in to comment.