review: merge async_update function with event property

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Quentame 2024-02-02 13:16:32 +01:00 committed by GitHub
parent 14ca00a3c5
commit 503505561d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 8 deletions

View File

@ -56,12 +56,13 @@ class EGSCalendar(CoordinatorEntity[EGSCalendarUpdateCoordinator], CalendarEntit
manufacturer="Epic Games Store",
name="Epic Games Store",
)
self._event: CalendarEvent | None = None
@property
def event(self) -> CalendarEvent | None:
"""Return the next upcoming event."""
return self._event
if event := self.coordinator.data[self._cal_type]:
return _get_calendar_event(event[0])
return None
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
@ -84,12 +85,6 @@ class EGSCalendar(CoordinatorEntity[EGSCalendarUpdateCoordinator], CalendarEntit
)
return [_get_calendar_event(event) for event in events]
async def async_update(self) -> None:
"""Update entity state with the next upcoming event."""
event: list[dict[str, Any]] = self.coordinator.data[self._cal_type]
if event:
self._event = _get_calendar_event(event[0])
def _get_calendar_event(event: dict[str, Any]) -> CalendarEvent:
"""Return a CalendarEvent from an API event."""