Skip to content

Commit

Permalink
Fix bug in calendar state transitions (#102083)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter authored Oct 15, 2023
1 parent 422252e commit ce7573c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions homeassistant/components/calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class CalendarEntity(Entity):

_entity_component_unrecorded_attributes = frozenset({"description"})

_alarm_unsubs: list[CALLBACK_TYPE] = []
_alarm_unsubs: list[CALLBACK_TYPE] | None = None

@property
def event(self) -> CalendarEvent | None:
Expand Down Expand Up @@ -528,6 +528,8 @@ def async_write_ha_state(self) -> None:
the current or upcoming event.
"""
super().async_write_ha_state()
if self._alarm_unsubs is None:
self._alarm_unsubs = []
_LOGGER.debug(
"Clearing %s alarms (%s)", self.entity_id, len(self._alarm_unsubs)
)
Expand Down Expand Up @@ -571,9 +573,9 @@ async def async_will_remove_from_hass(self) -> None:
To be extended by integrations.
"""
for unsub in self._alarm_unsubs:
for unsub in self._alarm_unsubs or ():
unsub()
self._alarm_unsubs.clear()
self._alarm_unsubs = None

async def async_get_events(
self,
Expand Down

0 comments on commit ce7573c

Please sign in to comment.