mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Move elmax base entity to separate module (#126481)
This commit is contained in:
parent
5a52e4c71d
commit
a9b215357f
@ -25,9 +25,9 @@ from homeassistant.exceptions import HomeAssistantError, InvalidStateError
|
||||
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(
|
||||
|
@ -12,9 +12,9 @@ from homeassistant.config_entries import ConfigEntry
|
||||
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(
|
||||
|
@ -4,15 +4,10 @@ from __future__ import annotations
|
||||
|
||||
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 @@ class DirectPanel(PanelEntry):
|
||||
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
|
||||
|
@ -13,9 +13,9 @@ from homeassistant.config_entries import ConfigEntry
|
||||
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__)
|
||||
|
||||
|
41
homeassistant/components/elmax/entity.py
Normal file
41
homeassistant/components/elmax/entity.py
Normal file
@ -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
|
@ -12,9 +12,9 @@ from homeassistant.config_entries import ConfigEntry
|
||||
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__)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user