From a9b215357fd399ca02c9cfba4d81c29b008b0005 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 23 Sep 2024 08:59:38 +0200 Subject: [PATCH] Move elmax base entity to separate module (#126481) --- .../components/elmax/alarm_control_panel.py | 2 +- .../components/elmax/binary_sensor.py | 2 +- homeassistant/components/elmax/common.py | 37 +---------------- homeassistant/components/elmax/cover.py | 2 +- homeassistant/components/elmax/entity.py | 41 +++++++++++++++++++ homeassistant/components/elmax/switch.py | 2 +- 6 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 homeassistant/components/elmax/entity.py diff --git a/homeassistant/components/elmax/alarm_control_panel.py b/homeassistant/components/elmax/alarm_control_panel.py index 61d137046418e..4162b1779754b 100644 --- a/homeassistant/components/elmax/alarm_control_panel.py +++ b/homeassistant/components/elmax/alarm_control_panel.py @@ -25,9 +25,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType -from .common import ElmaxEntity from .const import DOMAIN from .coordinator import ElmaxCoordinator +from .entity import ElmaxEntity async def async_setup_entry( diff --git a/homeassistant/components/elmax/binary_sensor.py b/homeassistant/components/elmax/binary_sensor.py index e477ab6c2a43c..ec51f861819e6 100644 --- a/homeassistant/components/elmax/binary_sensor.py +++ b/homeassistant/components/elmax/binary_sensor.py @@ -12,9 +12,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .common import ElmaxEntity from .const import DOMAIN from .coordinator import ElmaxCoordinator +from .entity import ElmaxEntity async def async_setup_entry( diff --git a/homeassistant/components/elmax/common.py b/homeassistant/components/elmax/common.py index 965e30235ff1c..88e61e36a683d 100644 --- a/homeassistant/components/elmax/common.py +++ b/homeassistant/components/elmax/common.py @@ -4,15 +4,10 @@ import ssl -from elmax_api.model.endpoint import DeviceEndpoint from elmax_api.model.panel import PanelEntry from packaging import version -from homeassistant.helpers.device_registry import DeviceInfo -from homeassistant.helpers.update_coordinator import CoordinatorEntity - -from .const import DOMAIN, ELMAX_LOCAL_API_PATH, MIN_APIV2_SUPPORTED_VERSION -from .coordinator import ElmaxCoordinator +from .const import ELMAX_LOCAL_API_PATH, MIN_APIV2_SUPPORTED_VERSION def get_direct_api_url(host: str, port: int, use_ssl: bool) -> str: @@ -47,33 +42,3 @@ def __init__(self, panel_uri): def get_name_by_user(self, username: str) -> str: """Return the panel name.""" return f"Direct Panel {self.hash}" - - -class ElmaxEntity(CoordinatorEntity[ElmaxCoordinator]): - """Wrapper for Elmax entities.""" - - def __init__( - self, - elmax_device: DeviceEndpoint, - panel_version: str, - coordinator: ElmaxCoordinator, - ) -> None: - """Construct the object.""" - super().__init__(coordinator=coordinator) - self._device = elmax_device - self._attr_unique_id = elmax_device.endpoint_id - self._attr_name = elmax_device.name - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, coordinator.panel_entry.hash)}, - name=coordinator.panel_entry.get_name_by_user( - coordinator.http_client.get_authenticated_username() - ), - manufacturer="Elmax", - model=panel_version, - sw_version=panel_version, - ) - - @property - def available(self) -> bool: - """Return if entity is available.""" - return super().available and self.coordinator.panel_entry.online diff --git a/homeassistant/components/elmax/cover.py b/homeassistant/components/elmax/cover.py index 528b2e6dead18..a53c28c5f338b 100644 --- a/homeassistant/components/elmax/cover.py +++ b/homeassistant/components/elmax/cover.py @@ -13,9 +13,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .common import ElmaxEntity from .const import DOMAIN from .coordinator import ElmaxCoordinator +from .entity import ElmaxEntity _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/elmax/entity.py b/homeassistant/components/elmax/entity.py new file mode 100644 index 0000000000000..a49fdc14c3e97 --- /dev/null +++ b/homeassistant/components/elmax/entity.py @@ -0,0 +1,41 @@ +"""Elmax integration common classes and utilities.""" + +from __future__ import annotations + +from elmax_api.model.endpoint import DeviceEndpoint + +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from .const import DOMAIN +from .coordinator import ElmaxCoordinator + + +class ElmaxEntity(CoordinatorEntity[ElmaxCoordinator]): + """Wrapper for Elmax entities.""" + + def __init__( + self, + elmax_device: DeviceEndpoint, + panel_version: str, + coordinator: ElmaxCoordinator, + ) -> None: + """Construct the object.""" + super().__init__(coordinator=coordinator) + self._device = elmax_device + self._attr_unique_id = elmax_device.endpoint_id + self._attr_name = elmax_device.name + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, coordinator.panel_entry.hash)}, + name=coordinator.panel_entry.get_name_by_user( + coordinator.http_client.get_authenticated_username() + ), + manufacturer="Elmax", + model=panel_version, + sw_version=panel_version, + ) + + @property + def available(self) -> bool: + """Return if entity is available.""" + return super().available and self.coordinator.panel_entry.online diff --git a/homeassistant/components/elmax/switch.py b/homeassistant/components/elmax/switch.py index 6ecbc70a8c550..d0e52c556f616 100644 --- a/homeassistant/components/elmax/switch.py +++ b/homeassistant/components/elmax/switch.py @@ -12,9 +12,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .common import ElmaxEntity from .const import DOMAIN from .coordinator import ElmaxCoordinator +from .entity import ElmaxEntity _LOGGER = logging.getLogger(__name__)