mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Move iaqualink base entity to separate module (#126100)
This commit is contained in:
parent
ecea251efa
commit
6dfa6b0001
@ -12,7 +12,6 @@ import httpx
|
|||||||
from iaqualink.client import AqualinkClient
|
from iaqualink.client import AqualinkClient
|
||||||
from iaqualink.device import (
|
from iaqualink.device import (
|
||||||
AqualinkBinarySensor,
|
AqualinkBinarySensor,
|
||||||
AqualinkDevice,
|
|
||||||
AqualinkLight,
|
AqualinkLight,
|
||||||
AqualinkSensor,
|
AqualinkSensor,
|
||||||
AqualinkSwitch,
|
AqualinkSwitch,
|
||||||
@ -29,16 +28,12 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.dispatcher import (
|
|
||||||
async_dispatcher_connect,
|
|
||||||
async_dispatcher_send,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
|
||||||
from .const import DOMAIN, UPDATE_INTERVAL
|
from .const import DOMAIN, UPDATE_INTERVAL
|
||||||
|
from .entity import AqualinkEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -194,44 +189,3 @@ def refresh_system[_AqualinkEntityT: AqualinkEntity, **_P](
|
|||||||
async_dispatcher_send(self.hass, DOMAIN)
|
async_dispatcher_send(self.hass, DOMAIN)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class AqualinkEntity(Entity):
|
|
||||||
"""Abstract class for all Aqualink platforms.
|
|
||||||
|
|
||||||
Entity state is updated via the interval timer within the integration.
|
|
||||||
Any entity state change via the iaqualink library triggers an internal
|
|
||||||
state refresh which is then propagated to all the entities in the system
|
|
||||||
via the refresh_system decorator above to the _update_callback in this
|
|
||||||
class.
|
|
||||||
"""
|
|
||||||
|
|
||||||
_attr_should_poll = False
|
|
||||||
|
|
||||||
def __init__(self, dev: AqualinkDevice) -> None:
|
|
||||||
"""Initialize the entity."""
|
|
||||||
self.dev = dev
|
|
||||||
self._attr_unique_id = f"{dev.system.serial}_{dev.name}"
|
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._attr_unique_id)},
|
|
||||||
manufacturer=dev.manufacturer,
|
|
||||||
model=dev.model,
|
|
||||||
name=dev.label,
|
|
||||||
via_device=(DOMAIN, dev.system.serial),
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Set up a listener when this entity is added to HA."""
|
|
||||||
self.async_on_remove(
|
|
||||||
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def assumed_state(self) -> bool:
|
|
||||||
"""Return whether the state is based on actual reading from the device."""
|
|
||||||
return self.dev.system.online in [False, None]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return whether the device is available or not."""
|
|
||||||
return self.dev.system.online is True
|
|
||||||
|
@ -13,8 +13,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity
|
|
||||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
|
from .entity import AqualinkEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
|
from .entity import AqualinkEntity
|
||||||
from .utils import await_or_reraise
|
from .utils import await_or_reraise
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
52
homeassistant/components/iaqualink/entity.py
Normal file
52
homeassistant/components/iaqualink/entity.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
"""Component to embed Aqualink devices."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from iaqualink.device import AqualinkDevice
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
class AqualinkEntity(Entity):
|
||||||
|
"""Abstract class for all Aqualink platforms.
|
||||||
|
|
||||||
|
Entity state is updated via the interval timer within the integration.
|
||||||
|
Any entity state change via the iaqualink library triggers an internal
|
||||||
|
state refresh which is then propagated to all the entities in the system
|
||||||
|
via the refresh_system decorator above to the _update_callback in this
|
||||||
|
class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(self, dev: AqualinkDevice) -> None:
|
||||||
|
"""Initialize the entity."""
|
||||||
|
self.dev = dev
|
||||||
|
self._attr_unique_id = f"{dev.system.serial}_{dev.name}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self._attr_unique_id)},
|
||||||
|
manufacturer=dev.manufacturer,
|
||||||
|
model=dev.model,
|
||||||
|
name=dev.label,
|
||||||
|
via_device=(DOMAIN, dev.system.serial),
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Set up a listener when this entity is added to HA."""
|
||||||
|
self.async_on_remove(
|
||||||
|
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def assumed_state(self) -> bool:
|
||||||
|
"""Return whether the state is based on actual reading from the device."""
|
||||||
|
return self.dev.system.online in [False, None]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return whether the device is available or not."""
|
||||||
|
return self.dev.system.online is True
|
@ -18,8 +18,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
|
from .entity import AqualinkEntity
|
||||||
from .utils import await_or_reraise
|
from .utils import await_or_reraise
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
@ -14,8 +14,8 @@ from homeassistant.const import UnitOfTemperature
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity
|
|
||||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
|
from .entity import AqualinkEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
|
from .entity import AqualinkEntity
|
||||||
from .utils import await_or_reraise
|
from .utils import await_or_reraise
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user