Add a calendar entity to Ridwell (#86117)

This commit is contained in:
Aaron Bach 2023-02-14 06:58:41 -07:00 committed by GitHub
parent e1a5d5a749
commit 16a5275461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 131 additions and 25 deletions

View file

@ -1,8 +1,12 @@
"""Define a base Ridwell entity."""
from __future__ import annotations
from datetime import date
from aioridwell.model import RidwellAccount, RidwellPickupEvent
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
@ -18,7 +22,6 @@ class RidwellEntity(CoordinatorEntity[RidwellDataUpdateCoordinator]):
self,
coordinator: RidwellDataUpdateCoordinator,
account: RidwellAccount,
description: EntityDescription,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
@ -31,10 +34,12 @@ class RidwellEntity(CoordinatorEntity[RidwellDataUpdateCoordinator]):
manufacturer="Ridwell",
name="Ridwell",
)
self._attr_unique_id = f"{account.account_id}_{description.key}"
self.entity_description = description
@property
def next_pickup_event(self) -> RidwellPickupEvent:
"""Get the next pickup event."""
return self.coordinator.data[self._account.account_id]
return next(
event
for event in self.coordinator.data[self._account.account_id]
if event.pickup_date >= date.today()
)