Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Define a base ReCollect Waste entity."""
2 
3 from aiorecollect.client import PickupEvent
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
8  CoordinatorEntity,
9  DataUpdateCoordinator,
10 )
11 
12 from .const import CONF_PLACE_ID, CONF_SERVICE_ID, DOMAIN
13 
14 
15 class ReCollectWasteEntity(CoordinatorEntity[DataUpdateCoordinator[list[PickupEvent]]]):
16  """Define a base ReCollect Waste entity."""
17 
18  _attr_has_entity_name = True
19 
20  def __init__(
21  self,
22  coordinator: DataUpdateCoordinator[list[PickupEvent]],
23  entry: ConfigEntry,
24  ) -> None:
25  """Initialize the sensor."""
26  super().__init__(coordinator)
27 
28  self._identifier_identifier = f"{entry.data[CONF_PLACE_ID]}_{entry.data[CONF_SERVICE_ID]}"
29 
30  self._attr_device_info_attr_device_info = DeviceInfo(
31  entry_type=DeviceEntryType.SERVICE,
32  identifiers={(DOMAIN, self._identifier_identifier)},
33  manufacturer="ReCollect Waste",
34  name="ReCollect Waste",
35  )
36  self._attr_extra_state_attributes_attr_extra_state_attributes = {}
37  self._entry_entry = entry
38 
39  async def async_added_to_hass(self) -> None:
40  """Run when entity about to be added to hass."""
41  await super().async_added_to_hass()
42  self._handle_coordinator_update()
None __init__(self, DataUpdateCoordinator[list[PickupEvent]] coordinator, ConfigEntry entry)
Definition: entity.py:24