Move omnilogic base entity to separate module (#126505)
parent
61de70c1df
commit
0163f3d57e
|
@ -1,97 +1,5 @@
|
|||
"""Common classes and elements for Omnilogic Integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OmniLogicUpdateCoordinator
|
||||
|
||||
|
||||
class OmniLogicEntity(CoordinatorEntity[OmniLogicUpdateCoordinator]):
|
||||
"""Defines the base OmniLogic entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: OmniLogicUpdateCoordinator,
|
||||
kind: str,
|
||||
name: str,
|
||||
item_id: tuple,
|
||||
icon: str,
|
||||
) -> None:
|
||||
"""Initialize the OmniLogic Entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
bow_id = None
|
||||
entity_data = coordinator.data[item_id]
|
||||
|
||||
backyard_id = item_id[:2]
|
||||
if len(item_id) == 6:
|
||||
bow_id = item_id[:4]
|
||||
|
||||
msp_system_id = coordinator.data[backyard_id]["systemId"]
|
||||
entity_friendly_name = f"{coordinator.data[backyard_id]['BackyardName']} "
|
||||
unique_id = f"{msp_system_id}"
|
||||
|
||||
if bow_id is not None:
|
||||
unique_id = f"{unique_id}_{coordinator.data[bow_id]['systemId']}"
|
||||
|
||||
if kind != "Heaters":
|
||||
entity_friendly_name = (
|
||||
f"{entity_friendly_name}{coordinator.data[bow_id]['Name']} "
|
||||
)
|
||||
else:
|
||||
entity_friendly_name = f"{entity_friendly_name}{coordinator.data[bow_id]['Operation']['VirtualHeater']['Name']} "
|
||||
|
||||
unique_id = f"{unique_id}_{coordinator.data[item_id]['systemId']}_{kind}"
|
||||
|
||||
if entity_data.get("Name") is not None:
|
||||
entity_friendly_name = f"{entity_friendly_name} {entity_data['Name']}"
|
||||
|
||||
entity_friendly_name = f"{entity_friendly_name} {name}"
|
||||
|
||||
unique_id = unique_id.replace(" ", "_")
|
||||
|
||||
self._kind = kind
|
||||
self._name = entity_friendly_name
|
||||
self._unique_id = unique_id
|
||||
self._item_id = item_id
|
||||
self._icon = icon
|
||||
self._attrs: dict[str, Any] = {}
|
||||
self._msp_system_id = msp_system_id
|
||||
self._backyard_name = coordinator.data[backyard_id]["BackyardName"]
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon for the entity."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the attributes."""
|
||||
return self._attrs
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Define the device as back yard/MSP System."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._msp_system_id)},
|
||||
manufacturer="Hayward",
|
||||
model="OmniLogic",
|
||||
name=self._backyard_name,
|
||||
)
|
||||
|
||||
|
||||
def check_guard(state_key, item, entity_setting):
|
||||
"""Validate that this entity passes the defined guard conditions defined at setup."""
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
"""Common classes and elements for Omnilogic Integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OmniLogicUpdateCoordinator
|
||||
|
||||
|
||||
class OmniLogicEntity(CoordinatorEntity[OmniLogicUpdateCoordinator]):
|
||||
"""Defines the base OmniLogic entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: OmniLogicUpdateCoordinator,
|
||||
kind: str,
|
||||
name: str,
|
||||
item_id: tuple,
|
||||
icon: str,
|
||||
) -> None:
|
||||
"""Initialize the OmniLogic Entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
bow_id = None
|
||||
entity_data = coordinator.data[item_id]
|
||||
|
||||
backyard_id = item_id[:2]
|
||||
if len(item_id) == 6:
|
||||
bow_id = item_id[:4]
|
||||
|
||||
msp_system_id = coordinator.data[backyard_id]["systemId"]
|
||||
entity_friendly_name = f"{coordinator.data[backyard_id]['BackyardName']} "
|
||||
unique_id = f"{msp_system_id}"
|
||||
|
||||
if bow_id is not None:
|
||||
unique_id = f"{unique_id}_{coordinator.data[bow_id]['systemId']}"
|
||||
|
||||
if kind != "Heaters":
|
||||
entity_friendly_name = (
|
||||
f"{entity_friendly_name}{coordinator.data[bow_id]['Name']} "
|
||||
)
|
||||
else:
|
||||
entity_friendly_name = f"{entity_friendly_name}{coordinator.data[bow_id]['Operation']['VirtualHeater']['Name']} "
|
||||
|
||||
unique_id = f"{unique_id}_{coordinator.data[item_id]['systemId']}_{kind}"
|
||||
|
||||
if entity_data.get("Name") is not None:
|
||||
entity_friendly_name = f"{entity_friendly_name} {entity_data['Name']}"
|
||||
|
||||
entity_friendly_name = f"{entity_friendly_name} {name}"
|
||||
|
||||
unique_id = unique_id.replace(" ", "_")
|
||||
|
||||
self._kind = kind
|
||||
self._name = entity_friendly_name
|
||||
self._unique_id = unique_id
|
||||
self._item_id = item_id
|
||||
self._icon = icon
|
||||
self._attrs: dict[str, Any] = {}
|
||||
self._msp_system_id = msp_system_id
|
||||
self._backyard_name = coordinator.data[backyard_id]["BackyardName"]
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon for the entity."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the attributes."""
|
||||
return self._attrs
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Define the device as back yard/MSP System."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._msp_system_id)},
|
||||
manufacturer="Hayward",
|
||||
model="OmniLogic",
|
||||
name=self._backyard_name,
|
||||
)
|
|
@ -15,9 +15,10 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .common import OmniLogicEntity, check_guard
|
||||
from .common import check_guard
|
||||
from .const import COORDINATOR, DEFAULT_PH_OFFSET, DOMAIN, PUMP_TYPES
|
||||
from .coordinator import OmniLogicUpdateCoordinator
|
||||
from .entity import OmniLogicEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
|
|
@ -12,9 +12,10 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .common import OmniLogicEntity, check_guard
|
||||
from .common import check_guard
|
||||
from .const import COORDINATOR, DOMAIN, PUMP_TYPES
|
||||
from .coordinator import OmniLogicUpdateCoordinator
|
||||
from .entity import OmniLogicEntity
|
||||
|
||||
SERVICE_SET_SPEED = "set_pump_speed"
|
||||
OMNILOGIC_SWITCH_OFF = 7
|
||||
|
|
Loading…
Reference in New Issue