mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Update local calendar to process calendar events in the executor (#144233)
This commit is contained in:
parent
c6b9a40234
commit
68d62ab58e
@ -94,20 +94,27 @@ class LocalCalendarEntity(CalendarEntity):
|
||||
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
|
||||
) -> list[CalendarEvent]:
|
||||
"""Get all events in a specific time frame."""
|
||||
|
||||
def events_in_range() -> list[CalendarEvent]:
|
||||
events = self._calendar.timeline_tz(start_date.tzinfo).overlapping(
|
||||
start_date,
|
||||
end_date,
|
||||
)
|
||||
return [_get_calendar_event(event) for event in events]
|
||||
|
||||
return await self.hass.async_add_executor_job(events_in_range)
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update entity state with the next upcoming event."""
|
||||
|
||||
def next_event() -> CalendarEvent | None:
|
||||
now = dt_util.now()
|
||||
events = self._calendar.timeline_tz(now.tzinfo).active_after(now)
|
||||
if event := next(events, None):
|
||||
self._event = _get_calendar_event(event)
|
||||
else:
|
||||
self._event = None
|
||||
return _get_calendar_event(event)
|
||||
return None
|
||||
|
||||
self._event = await self.hass.async_add_executor_job(next_event)
|
||||
|
||||
async def _async_store(self) -> None:
|
||||
"""Persist the calendar to disk."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user