From 93de46b50e2948c097c3a6c25c16bf35d4375f32 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:51:05 +0200 Subject: [PATCH] Move velux base entity to separate module (#126185) --- homeassistant/components/velux/__init__.py | 35 ++------------------- homeassistant/components/velux/cover.py | 3 +- homeassistant/components/velux/entity.py | 36 ++++++++++++++++++++++ homeassistant/components/velux/light.py | 3 +- homeassistant/components/velux/scene.py | 2 +- 5 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 homeassistant/components/velux/entity.py diff --git a/homeassistant/components/velux/__init__.py b/homeassistant/components/velux/__init__.py index 614ed810429..2f1cab67c16 100644 --- a/homeassistant/components/velux/__init__.py +++ b/homeassistant/components/velux/__init__.py @@ -1,11 +1,10 @@ """Support for VELUX KLF 200 devices.""" -from pyvlx import Node, PyVLX, PyVLXException +from pyvlx import PyVLX, PyVLXException from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.helpers.entity import Entity +from homeassistant.core import HomeAssistant, ServiceCall from .const import DOMAIN, LOGGER, PLATFORMS @@ -67,33 +66,3 @@ class VeluxModule: LOGGER.debug("Velux interface started") await self.pyvlx.load_scenes() await self.pyvlx.load_nodes() - - -class VeluxEntity(Entity): - """Abstraction for al Velux entities.""" - - _attr_should_poll = False - - def __init__(self, node: Node, config_entry_id: str) -> None: - """Initialize the Velux device.""" - self.node = node - self._attr_unique_id = ( - node.serial_number - if node.serial_number - else f"{config_entry_id}_{node.node_id}" - ) - self._attr_name = node.name if node.name else f"#{node.node_id}" - - @callback - def async_register_callbacks(self): - """Register callbacks to update hass after device was changed.""" - - async def after_update_callback(device): - """Call after device was updated.""" - self.async_write_ha_state() - - self.node.register_device_updated_cb(after_update_callback) - - async def async_added_to_hass(self): - """Store register state change callback.""" - self.async_register_callbacks() diff --git a/homeassistant/components/velux/cover.py b/homeassistant/components/velux/cover.py index cd7564eee81..2e74441c873 100644 --- a/homeassistant/components/velux/cover.py +++ b/homeassistant/components/velux/cover.py @@ -18,7 +18,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import DOMAIN, VeluxEntity +from .const import DOMAIN +from .entity import VeluxEntity PARALLEL_UPDATES = 1 diff --git a/homeassistant/components/velux/entity.py b/homeassistant/components/velux/entity.py new file mode 100644 index 00000000000..674ba5dde45 --- /dev/null +++ b/homeassistant/components/velux/entity.py @@ -0,0 +1,36 @@ +"""Support for VELUX KLF 200 devices.""" + +from pyvlx import Node + +from homeassistant.core import callback +from homeassistant.helpers.entity import Entity + + +class VeluxEntity(Entity): + """Abstraction for al Velux entities.""" + + _attr_should_poll = False + + def __init__(self, node: Node, config_entry_id: str) -> None: + """Initialize the Velux device.""" + self.node = node + self._attr_unique_id = ( + node.serial_number + if node.serial_number + else f"{config_entry_id}_{node.node_id}" + ) + self._attr_name = node.name if node.name else f"#{node.node_id}" + + @callback + def async_register_callbacks(self): + """Register callbacks to update hass after device was changed.""" + + async def after_update_callback(device): + """Call after device was updated.""" + self.async_write_ha_state() + + self.node.register_device_updated_cb(after_update_callback) + + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() diff --git a/homeassistant/components/velux/light.py b/homeassistant/components/velux/light.py index e98632701f3..14f12a01060 100644 --- a/homeassistant/components/velux/light.py +++ b/homeassistant/components/velux/light.py @@ -11,7 +11,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import DOMAIN, VeluxEntity +from .const import DOMAIN +from .entity import VeluxEntity PARALLEL_UPDATES = 1 diff --git a/homeassistant/components/velux/scene.py b/homeassistant/components/velux/scene.py index 30858b25002..54888413613 100644 --- a/homeassistant/components/velux/scene.py +++ b/homeassistant/components/velux/scene.py @@ -9,7 +9,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import DOMAIN +from .const import DOMAIN PARALLEL_UPDATES = 1