Skip to content

Commit d4ffeed

Browse files
allenporterfrenck
authored andcommitted
Partial revert of update to remote calendar to fix issue where calendar does not update (home-assistant#146702)
Partial revert
1 parent cb74b26 commit d4ffeed

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

homeassistant/components/remote_calendar/calendar.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55

66
from ical.event import Event
7+
from ical.timeline import Timeline
78

89
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
910
from homeassistant.core import HomeAssistant
@@ -48,12 +49,18 @@ def __init__(
4849
super().__init__(coordinator)
4950
self._attr_name = entry.data[CONF_CALENDAR_NAME]
5051
self._attr_unique_id = entry.entry_id
51-
self._event: CalendarEvent | None = None
52+
self._timeline: Timeline | None = None
5253

5354
@property
5455
def event(self) -> CalendarEvent | None:
5556
"""Return the next upcoming event."""
56-
return self._event
57+
if self._timeline is None:
58+
return None
59+
now = dt_util.now()
60+
events = self._timeline.active_after(now)
61+
if event := next(events, None):
62+
return _get_calendar_event(event)
63+
return None
5764

5865
async def async_get_events(
5966
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
@@ -79,15 +86,12 @@ async def async_update(self) -> None:
7986
"""
8087
await super().async_update()
8188

82-
def next_timeline_event() -> CalendarEvent | None:
89+
def _get_timeline() -> Timeline | None:
8390
"""Return the next active event."""
8491
now = dt_util.now()
85-
events = self.coordinator.data.timeline_tz(now.tzinfo).active_after(now)
86-
if event := next(events, None):
87-
return _get_calendar_event(event)
88-
return None
92+
return self.coordinator.data.timeline_tz(now.tzinfo)
8993

90-
self._event = await self.hass.async_add_executor_job(next_timeline_event)
94+
self._timeline = await self.hass.async_add_executor_job(_get_timeline)
9195

9296

9397
def _get_calendar_event(event: Event) -> CalendarEvent:

0 commit comments

Comments
 (0)