Clear calendar alarms after scheduling and add debug loggging (#101176)

pull/101386/head
Allen Porter 2023-10-01 06:25:04 -07:00 committed by Franck Nijhof
parent b27097808d
commit b20f9c40be
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
1 changed files with 10 additions and 0 deletions

View File

@ -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,