From 87ecdfb84f97ee36fb3710588be4b66910b954b7 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 1 Oct 2023 06:25:04 -0700 Subject: [PATCH] Clear calendar alarms after scheduling and add debug loggging (#101176) --- homeassistant/components/calendar/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 96872e039e1..1622f568a2d 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -531,6 +531,7 @@ class CalendarEntity(Entity): for unsub in self._alarm_unsubs: unsub() + self._alarm_unsubs.clear() now = dt_util.now() event = self.event @@ -540,6 +541,7 @@ class CalendarEntity(Entity): @callback def update(_: datetime.datetime) -> None: """Run when the active or upcoming event starts or ends.""" + _LOGGER.debug("Running %s update", self.entity_id) self._async_write_ha_state() if now < event.start_datetime_local: @@ -553,6 +555,13 @@ class CalendarEntity(Entity): self._alarm_unsubs.append( async_track_point_in_time(self.hass, update, event.end_datetime_local) ) + _LOGGER.debug( + "Scheduled %d updates for %s (%s, %s)", + len(self._alarm_unsubs), + self.entity_id, + event.start_datetime_local, + event.end_datetime_local, + ) async def async_will_remove_from_hass(self) -> None: """Run when entity will be removed from hass. @@ -561,6 +570,7 @@ class CalendarEntity(Entity): """ for unsub in self._alarm_unsubs: unsub() + self._alarm_unsubs.clear() async def async_get_events( self,