Partial revert of update to remote calendar to fix issue where calendar does not update (#146702)

Partial revert
This commit is contained in:
Allen Porter 2025-06-13 03:47:56 -07:00 committed by GitHub
parent 5ef99a15a5
commit e70a2dd257
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ from datetime import datetime
import logging
from ical.event import Event
from ical.timeline import Timeline
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
from homeassistant.core import HomeAssistant
@ -48,12 +49,18 @@ class RemoteCalendarEntity(
super().__init__(coordinator)
self._attr_name = entry.data[CONF_CALENDAR_NAME]
self._attr_unique_id = entry.entry_id
self._event: CalendarEvent | None = None
self._timeline: Timeline | None = None
@property
def event(self) -> CalendarEvent | None:
"""Return the next upcoming event."""
return self._event
if self._timeline is None:
return None
now = dt_util.now()
events = self._timeline.active_after(now)
if event := next(events, None):
return _get_calendar_event(event)
return None
async def async_get_events(
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
@ -79,15 +86,12 @@ class RemoteCalendarEntity(
"""
await super().async_update()
def next_timeline_event() -> CalendarEvent | None:
def _get_timeline() -> Timeline | None:
"""Return the next active event."""
now = dt_util.now()
events = self.coordinator.data.timeline_tz(now.tzinfo).active_after(now)
if event := next(events, None):
return _get_calendar_event(event)
return None
return self.coordinator.data.timeline_tz(now.tzinfo)
self._event = await self.hass.async_add_executor_job(next_timeline_event)
self._timeline = await self.hass.async_add_executor_job(_get_timeline)
def _get_calendar_event(event: Event) -> CalendarEvent: