Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for EcoNet products."""
2 
3 from homeassistant.core import callback
4 from homeassistant.helpers.device_registry import DeviceInfo
5 from homeassistant.helpers.dispatcher import async_dispatcher_connect
6 from homeassistant.helpers.entity import Entity
7 
8 from .const import DOMAIN, PUSH_UPDATE
9 
10 
12  """Define a base EcoNet entity."""
13 
14  _attr_should_poll = False
15 
16  def __init__(self, econet):
17  """Initialize."""
18  self._econet_econet = econet
19  self._attr_name_attr_name = econet.device_name
20  self._attr_unique_id_attr_unique_id = f"{econet.device_id}_{econet.device_name}"
21 
22  async def async_added_to_hass(self):
23  """Subscribe to device events."""
24  await super().async_added_to_hass()
25  self.async_on_removeasync_on_remove(
26  async_dispatcher_connect(self.hasshass, PUSH_UPDATE, self.on_update_receivedon_update_received)
27  )
28 
29  @callback
30  def on_update_received(self):
31  """Update was pushed from the ecoent API."""
32  self.async_write_ha_stateasync_write_ha_state()
33 
34  @property
35  def available(self):
36  """Return if the device is online or not."""
37  return self._econet_econet.connected
38 
39  @property
40  def device_info(self) -> DeviceInfo:
41  """Return device registry information for this entity."""
42  return DeviceInfo(
43  identifiers={(DOMAIN, self._econet_econet.device_id)},
44  manufacturer="Rheem",
45  name=self._econet_econet.device_name,
46  )
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