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
|
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
|
||||||
) -> list[CalendarEvent]:
|
) -> list[CalendarEvent]:
|
||||||
"""Get all events in a specific time frame."""
|
"""Get all events in a specific time frame."""
|
||||||
events = self._calendar.timeline_tz(start_date.tzinfo).overlapping(
|
|
||||||
start_date,
|
def events_in_range() -> list[CalendarEvent]:
|
||||||
end_date,
|
events = self._calendar.timeline_tz(start_date.tzinfo).overlapping(
|
||||||
)
|
start_date,
|
||||||
return [_get_calendar_event(event) for event in events]
|
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:
|
async def async_update(self) -> None:
|
||||||
"""Update entity state with the next upcoming event."""
|
"""Update entity state with the next upcoming event."""
|
||||||
now = dt_util.now()
|
|
||||||
events = self._calendar.timeline_tz(now.tzinfo).active_after(now)
|
def next_event() -> CalendarEvent | None:
|
||||||
if event := next(events, None):
|
now = dt_util.now()
|
||||||
self._event = _get_calendar_event(event)
|
events = self._calendar.timeline_tz(now.tzinfo).active_after(now)
|
||||||
else:
|
if event := next(events, None):
|
||||||
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:
|
async def _async_store(self) -> None:
|
||||||
"""Persist the calendar to disk."""
|
"""Persist the calendar to disk."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user