Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Common opentherm_gw entity properties."""
2 
3 import logging
4 
5 import pyotgw.vars as gw_vars
6 
7 from homeassistant.core import callback
8 from homeassistant.helpers.device_registry import DeviceInfo
9 from homeassistant.helpers.dispatcher import async_dispatcher_connect
10 from homeassistant.helpers.entity import Entity, EntityDescription
11 
12 from . import OpenThermGatewayHub
13 from .const import DOMAIN, OpenThermDataSource, OpenThermDeviceDescription
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 TRANSLATE_SOURCE = {
18  gw_vars.BOILER: "Boiler",
19  gw_vars.OTGW: None,
20  gw_vars.THERMOSTAT: "Thermostat",
21 }
22 
23 
25  """Describe common opentherm_gw entity properties."""
26 
27  device_description: OpenThermDeviceDescription
28 
29 
31  """Represent an OpenTherm entity."""
32 
33  _attr_has_entity_name = True
34  _attr_should_poll = False
35  entity_description: OpenThermEntityDescription
36 
37  def __init__(
38  self,
39  gw_hub: OpenThermGatewayHub,
40  description: OpenThermEntityDescription,
41  ) -> None:
42  """Initialize the entity."""
43  self.entity_descriptionentity_description = description
44  self._gateway_gateway = gw_hub
45  self._attr_unique_id_attr_unique_id = f"{gw_hub.hub_id}-{description.device_description.device_identifier}-{description.key}"
46  self._attr_device_info_attr_device_info = DeviceInfo(
47  identifiers={
48  (
49  DOMAIN,
50  f"{gw_hub.hub_id}-{description.device_description.device_identifier}",
51  )
52  },
53  )
54 
55  @property
56  def available(self) -> bool:
57  """Return connection status of the hub to indicate availability."""
58  return self._gateway_gateway.connected
59 
60 
62  """Represent an OpenTherm entity that receives status updates."""
63 
64  async def async_added_to_hass(self) -> None:
65  """Subscribe to updates from the component."""
66  self.async_on_removeasync_on_remove(
68  self.hasshass, self._gateway_gateway.update_signal, self.receive_reportreceive_report
69  )
70  )
71 
72  @callback
73  def receive_report(self, status: dict[OpenThermDataSource, dict]) -> None:
74  """Handle status updates from the component."""
75  # Must be implemented at the platform level.
76  raise NotImplementedError
None __init__(self, OpenThermGatewayHub gw_hub, OpenThermEntityDescription description)
Definition: entity.py:41
None receive_report(self, dict[OpenThermDataSource, dict] status)
Definition: entity.py:73
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