Skip to content

Commit

Permalink
Move elmax base entity to separate module (#126481)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Sep 23, 2024
1 parent 5a52e4c commit a9b2153
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/elmax/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/elmax/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 1 addition & 36 deletions homeassistant/components/elmax/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/elmax/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
41 changes: 41 additions & 0 deletions homeassistant/components/elmax/entity.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/elmax/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down

0 comments on commit a9b2153

Please sign in to comment.