Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """The AirVisual component."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.core import callback
7 from homeassistant.helpers.entity import EntityDescription
9  CoordinatorEntity,
10  DataUpdateCoordinator,
11 )
12 
13 
15  """Define a generic AirVisual entity."""
16 
17  def __init__(
18  self,
19  coordinator: DataUpdateCoordinator,
20  entry: ConfigEntry,
21  description: EntityDescription,
22  ) -> None:
23  """Initialize."""
24  super().__init__(coordinator)
25 
26  self._attr_extra_state_attributes_attr_extra_state_attributes = {}
27  self._entry_entry = entry
28  self.entity_descriptionentity_description = description
29 
30  async def async_added_to_hass(self) -> None:
31  """Register callbacks."""
32  await super().async_added_to_hass()
33 
34  @callback
35  def update() -> None:
36  """Update the state."""
37  self.update_from_latest_dataupdate_from_latest_data()
38  self.async_write_ha_state()
39 
40  self.async_on_remove(self.coordinator.async_add_listener(update))
41 
42  self.update_from_latest_dataupdate_from_latest_data()
43 
44  @callback
45  def update_from_latest_data(self) -> None:
46  """Update the entity from the latest data."""
47  raise NotImplementedError
None __init__(self, DataUpdateCoordinator coordinator, ConfigEntry entry, EntityDescription description)
Definition: entity.py:22
None async_add_listener(HomeAssistant hass, Callable[[], None] listener)
Definition: __init__.py:82