Skip to content

Commit

Permalink
Feat: Calendar updates refresh event sensors
Browse files Browse the repository at this point in the history
Event sensors no longer call a refresh of the event calendar, instead,
the event calendar will trigger a refresh of event sensors making them
more responsive to updates in the calendar.

Issue: Fixes #163
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
  • Loading branch information
tykeal committed Sep 27, 2023
1 parent 644211f commit f31c2ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 7 additions & 0 deletions custom_components/rental_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,10 @@ async def _refresh_calendar(self) -> None:
_LOGGER.error(
"%s returned %s - %s", self.url, response.status, response.reason
)

# Calendar has failed to load for some reason, unflag the calendar
# being loaded
self.calendar_loaded = False
else:
text = await response.text()
# Some calendars are for some reason filled with NULL-bytes.
Expand Down Expand Up @@ -842,3 +846,6 @@ async def _refresh_calendar(self) -> None:
)
self.event = event
found_next_event = True

# signal an update to all the event sensors
await asyncio.gather(*[event.async_update() for event in self.event_sensors])
2 changes: 0 additions & 2 deletions custom_components/rental_control/sensors/calsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ async def async_update(self):
if not self.rental_control_events.calendar_ready:
return

await self.rental_control_events.update()

self._code_generator = self.rental_control_events.code_generator
self._code_length = self.rental_control_events.code_length
event_list = self.rental_control_events.calendar
Expand Down

0 comments on commit f31c2ce

Please sign in to comment.