mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Use shorthand attrs for velux (#100294)
* Use shorthand attrs for velux * Update homeassistant/components/velux/cover.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * black --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
f2f45380a9
commit
871800778f
@ -1,7 +1,7 @@
|
|||||||
"""Support for VELUX KLF 200 devices."""
|
"""Support for VELUX KLF 200 devices."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyvlx import PyVLX, PyVLXException
|
from pyvlx import OpeningDevice, PyVLX, PyVLXException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -90,9 +90,11 @@ class VeluxEntity(Entity):
|
|||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, node):
|
def __init__(self, node: OpeningDevice) -> None:
|
||||||
"""Initialize the Velux device."""
|
"""Initialize the Velux device."""
|
||||||
self.node = node
|
self.node = node
|
||||||
|
self._attr_unique_id = node.serial_number
|
||||||
|
self._attr_name = node.name if node.name else "#" + str(node.node_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_register_callbacks(self):
|
def async_register_callbacks(self):
|
||||||
@ -107,15 +109,3 @@ class VeluxEntity(Entity):
|
|||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Store register state change callback."""
|
"""Store register state change callback."""
|
||||||
self.async_register_callbacks()
|
self.async_register_callbacks()
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return the unique id base on the serial_id returned by Velux."""
|
|
||||||
return self.node.serial_number
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the Velux device."""
|
|
||||||
if not self.node.name:
|
|
||||||
return "#" + str(self.node.node_id)
|
|
||||||
return self.node.name
|
|
||||||
|
@ -39,6 +39,26 @@ async def async_setup_platform(
|
|||||||
class VeluxCover(VeluxEntity, CoverEntity):
|
class VeluxCover(VeluxEntity, CoverEntity):
|
||||||
"""Representation of a Velux cover."""
|
"""Representation of a Velux cover."""
|
||||||
|
|
||||||
|
_is_blind = False
|
||||||
|
|
||||||
|
def __init__(self, node: OpeningDevice) -> None:
|
||||||
|
"""Initialize VeluxCover."""
|
||||||
|
super().__init__(node)
|
||||||
|
self._attr_device_class = CoverDeviceClass.WINDOW
|
||||||
|
if isinstance(node, Awning):
|
||||||
|
self._attr_device_class = CoverDeviceClass.AWNING
|
||||||
|
if isinstance(node, Blind):
|
||||||
|
self._attr_device_class = CoverDeviceClass.BLIND
|
||||||
|
self._is_blind = True
|
||||||
|
if isinstance(node, GarageDoor):
|
||||||
|
self._attr_device_class = CoverDeviceClass.GARAGE
|
||||||
|
if isinstance(node, Gate):
|
||||||
|
self._attr_device_class = CoverDeviceClass.GATE
|
||||||
|
if isinstance(node, RollerShutter):
|
||||||
|
self._attr_device_class = CoverDeviceClass.SHUTTER
|
||||||
|
if isinstance(node, Window):
|
||||||
|
self._attr_device_class = CoverDeviceClass.WINDOW
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> CoverEntityFeature:
|
def supported_features(self) -> CoverEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
@ -65,27 +85,10 @@ class VeluxCover(VeluxEntity, CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def current_cover_tilt_position(self) -> int | None:
|
def current_cover_tilt_position(self) -> int | None:
|
||||||
"""Return the current position of the cover."""
|
"""Return the current position of the cover."""
|
||||||
if isinstance(self.node, Blind):
|
if self._is_blind:
|
||||||
return 100 - self.node.orientation.position_percent
|
return 100 - self.node.orientation.position_percent
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> CoverDeviceClass:
|
|
||||||
"""Define this cover as either awning, blind, garage, gate, shutter or window."""
|
|
||||||
if isinstance(self.node, Awning):
|
|
||||||
return CoverDeviceClass.AWNING
|
|
||||||
if isinstance(self.node, Blind):
|
|
||||||
return CoverDeviceClass.BLIND
|
|
||||||
if isinstance(self.node, GarageDoor):
|
|
||||||
return CoverDeviceClass.GARAGE
|
|
||||||
if isinstance(self.node, Gate):
|
|
||||||
return CoverDeviceClass.GATE
|
|
||||||
if isinstance(self.node, RollerShutter):
|
|
||||||
return CoverDeviceClass.SHUTTER
|
|
||||||
if isinstance(self.node, Window):
|
|
||||||
return CoverDeviceClass.WINDOW
|
|
||||||
return CoverDeviceClass.WINDOW
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self) -> bool:
|
def is_closed(self) -> bool:
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user