Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Component to embed Aqualink devices."""
2 
3 from __future__ import annotations
4 
5 from iaqualink.device import AqualinkDevice
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.dispatcher import async_dispatcher_connect
9 from homeassistant.helpers.entity import Entity
10 
11 from .const import DOMAIN
12 
13 
15  """Abstract class for all Aqualink platforms.
16 
17  Entity state is updated via the interval timer within the integration.
18  Any entity state change via the iaqualink library triggers an internal
19  state refresh which is then propagated to all the entities in the system
20  via the refresh_system decorator above to the _update_callback in this
21  class.
22  """
23 
24  _attr_should_poll = False
25 
26  def __init__(self, dev: AqualinkDevice) -> None:
27  """Initialize the entity."""
28  self.devdev = dev
29  self._attr_unique_id_attr_unique_id = f"{dev.system.serial}_{dev.name}"
30  self._attr_device_info_attr_device_info = DeviceInfo(
31  identifiers={(DOMAIN, self._attr_unique_id_attr_unique_id)},
32  manufacturer=dev.manufacturer,
33  model=dev.model,
34  name=dev.label,
35  via_device=(DOMAIN, dev.system.serial),
36  )
37 
38  async def async_added_to_hass(self) -> None:
39  """Set up a listener when this entity is added to HA."""
40  self.async_on_removeasync_on_remove(
41  async_dispatcher_connect(self.hasshass, DOMAIN, self.async_write_ha_stateasync_write_ha_state)
42  )
43 
44  @property
45  def assumed_state(self) -> bool:
46  """Return whether the state is based on actual reading from the device."""
47  return self.devdev.system.online in [False, None]
48 
49  @property
50  def available(self) -> bool:
51  """Return whether the device is available or not."""
52  return self.devdev.system.online is True
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103