Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """The base entity for the A. O. Smith integration."""
2 
3 from py_aosmith import AOSmithAPIClient
4 from py_aosmith.models import Device as AOSmithDevice
5 
6 from homeassistant.helpers.device_registry import DeviceInfo
7 from homeassistant.helpers.update_coordinator import CoordinatorEntity
8 
9 from .const import DOMAIN
10 from .coordinator import AOSmithEnergyCoordinator, AOSmithStatusCoordinator
11 
12 
14  _AOSmithCoordinatorT: AOSmithStatusCoordinator | AOSmithEnergyCoordinator
15 ](CoordinatorEntity[_AOSmithCoordinatorT]):
16  """Base entity for A. O. Smith."""
17 
18  _attr_has_entity_name = True
19 
20  def __init__(self, coordinator: _AOSmithCoordinatorT, junction_id: str) -> None:
21  """Initialize the entity."""
22  super().__init__(coordinator)
23  self.junction_id = junction_id
24  self._attr_device_info = DeviceInfo(
25  identifiers={(DOMAIN, junction_id)},
26  )
27 
28  @property
29  def client(self) -> AOSmithAPIClient:
30  """Shortcut to get the API client."""
31  return self.coordinator.client
32 
33 
34 class AOSmithStatusEntity(AOSmithEntity[AOSmithStatusCoordinator]):
35  """Base entity for entities that use data from the status coordinator."""
36 
37  @property
38  def device(self) -> AOSmithDevice:
39  """Shortcut to get the device from the coordinator data."""
40  return self.coordinator.data[self.junction_id]
41 
42  @property
43  def available(self) -> bool:
44  """Return True if entity is available."""
45  return super().available and self.devicedevice.status.is_online
46 
47 
48 class AOSmithEnergyEntity(AOSmithEntity[AOSmithEnergyCoordinator]):
49  """Base entity for entities that use data from the energy coordinator."""
50 
51  @property
52  def energy_usage(self) -> float:
53  """Shortcut to get the energy usage from the coordinator data."""
54  return self.coordinator.data[self.junction_id]
AOSmithAPIClient client(self)
Definition: entity.py:29
None __init__(self, _AOSmithCoordinatorT coordinator, str junction_id)
Definition: entity.py:20