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

This commit is contained in:
Allen Porter 2023-10-01 06:25:04 -07:00 committed by GitHub
parent 5e6735ab6d
commit 87ecdfb84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,