Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Define a base Ridwell entity."""
2 
3 from __future__ import annotations
4 
5 from datetime import date
6 
7 from aioridwell.model import RidwellAccount, RidwellPickupEvent
8 
9 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
10 from homeassistant.helpers.update_coordinator import CoordinatorEntity
11 
12 from .const import DOMAIN
13 from .coordinator import RidwellDataUpdateCoordinator
14 
15 
16 class RidwellEntity(CoordinatorEntity[RidwellDataUpdateCoordinator]):
17  """Define a base Ridwell entity."""
18 
19  _attr_has_entity_name = True
20 
21  def __init__(
22  self,
23  coordinator: RidwellDataUpdateCoordinator,
24  account: RidwellAccount,
25  ) -> None:
26  """Initialize the sensor."""
27  super().__init__(coordinator)
28 
29  self._account_account = account
30  self._attr_device_info_attr_device_info = DeviceInfo(
31  configuration_url=coordinator.dashboard_url,
32  entry_type=DeviceEntryType.SERVICE,
33  identifiers={(DOMAIN, coordinator.user_id)},
34  manufacturer="Ridwell",
35  name="Ridwell",
36  )
37 
38  @property
39  def next_pickup_event(self) -> RidwellPickupEvent:
40  """Get the next pickup event."""
41  return next(
42  event
43  for event in self.coordinator.data[self._account_account.account_id]
44  if event.pickup_date >= date.today()
45  )
None __init__(self, RidwellDataUpdateCoordinator coordinator, RidwellAccount account)
Definition: entity.py:25