diff --git a/homeassistant/components/iaqualink/__init__.py b/homeassistant/components/iaqualink/__init__.py index 36235d52ed797..26bffc4e982e2 100644 --- a/homeassistant/components/iaqualink/__init__.py +++ b/homeassistant/components/iaqualink/__init__.py @@ -12,7 +12,6 @@ from iaqualink.client import AqualinkClient from iaqualink.device import ( AqualinkBinarySensor, - AqualinkDevice, AqualinkLight, AqualinkSensor, AqualinkSwitch, @@ -29,16 +28,12 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers.device_registry import DeviceInfo -from homeassistant.helpers.dispatcher import ( - async_dispatcher_connect, - async_dispatcher_send, -) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.httpx_client import get_async_client from .const import DOMAIN, UPDATE_INTERVAL +from .entity import AqualinkEntity _LOGGER = logging.getLogger(__name__) @@ -194,44 +189,3 @@ async def wrapper( async_dispatcher_send(self.hass, DOMAIN) 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 diff --git a/homeassistant/components/iaqualink/binary_sensor.py b/homeassistant/components/iaqualink/binary_sensor.py index 92e152701a401..9e173dc36e0c2 100644 --- a/homeassistant/components/iaqualink/binary_sensor.py +++ b/homeassistant/components/iaqualink/binary_sensor.py @@ -13,8 +13,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import AqualinkEntity from .const import DOMAIN as AQUALINK_DOMAIN +from .entity import AqualinkEntity PARALLEL_UPDATES = 0 diff --git a/homeassistant/components/iaqualink/climate.py b/homeassistant/components/iaqualink/climate.py index 8ed3026e72efa..78da1eff0713e 100644 --- a/homeassistant/components/iaqualink/climate.py +++ b/homeassistant/components/iaqualink/climate.py @@ -20,8 +20,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import AqualinkEntity, refresh_system +from . import refresh_system from .const import DOMAIN as AQUALINK_DOMAIN +from .entity import AqualinkEntity from .utils import await_or_reraise _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/iaqualink/entity.py b/homeassistant/components/iaqualink/entity.py new file mode 100644 index 0000000000000..437611e5a5ffb --- /dev/null +++ b/homeassistant/components/iaqualink/entity.py @@ -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 diff --git a/homeassistant/components/iaqualink/light.py b/homeassistant/components/iaqualink/light.py index 74ffe489a51ea..59172c1357605 100644 --- a/homeassistant/components/iaqualink/light.py +++ b/homeassistant/components/iaqualink/light.py @@ -18,8 +18,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import AqualinkEntity, refresh_system +from . import refresh_system from .const import DOMAIN as AQUALINK_DOMAIN +from .entity import AqualinkEntity from .utils import await_or_reraise PARALLEL_UPDATES = 0 diff --git a/homeassistant/components/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index 35dc01928ec67..881adb420bf72 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -14,8 +14,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import AqualinkEntity from .const import DOMAIN as AQUALINK_DOMAIN +from .entity import AqualinkEntity PARALLEL_UPDATES = 0 diff --git a/homeassistant/components/iaqualink/switch.py b/homeassistant/components/iaqualink/switch.py index 43b35b456a372..601c5701a4afb 100644 --- a/homeassistant/components/iaqualink/switch.py +++ b/homeassistant/components/iaqualink/switch.py @@ -11,8 +11,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import AqualinkEntity, refresh_system +from . import refresh_system from .const import DOMAIN as AQUALINK_DOMAIN +from .entity import AqualinkEntity from .utils import await_or_reraise PARALLEL_UPDATES = 0