Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Balboa entities."""
2 
3 from __future__ import annotations
4 
5 from pybalboa import EVENT_UPDATE, SpaClient
6 
7 from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
8 from homeassistant.helpers.entity import Entity
9 
10 from .const import DOMAIN
11 
12 
14  """Balboa base entity."""
15 
16  _attr_should_poll = False
17  _attr_has_entity_name = True
18 
19  def __init__(self, client: SpaClient, key: str) -> None:
20  """Initialize the control."""
21  mac = client.mac_address
22  model = client.model
23  self._attr_unique_id_attr_unique_id = f'{model}-{key}-{mac.replace(":","")[-6:]}'
24  self._attr_device_info_attr_device_info = DeviceInfo(
25  identifiers={(DOMAIN, mac)},
26  name=model,
27  manufacturer="Balboa Water Group",
28  model=model,
29  sw_version=client.software_version,
30  connections={(CONNECTION_NETWORK_MAC, mac)},
31  )
32  self._client_client = client
33 
34  @property
35  def assumed_state(self) -> bool:
36  """Return whether the state is based on actual reading from device."""
37  return not self._client_client.available
38 
39  async def async_added_to_hass(self) -> None:
40  """Run when entity about to be added to hass."""
41  self.async_on_removeasync_on_remove(self._client_client.on(EVENT_UPDATE, self.async_write_ha_stateasync_write_ha_state))
None __init__(self, SpaClient client, str key)
Definition: entity.py:19
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331