Skip to content

Commit

Permalink
Merge pull request #136 from tykeal/calendar_cache
Browse files Browse the repository at this point in the history
Fix: Prevent inaccessible calendars from deleting
  • Loading branch information
tykeal authored Oct 6, 2022
2 parents 4dd8cb3 + f23fb74 commit 1c888da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion custom_components/rental_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def __init__(self, hass, config, unique_id):
self.verify_ssl = config.get(CONF_VERIFY_SSL)
self.calendar = []
self.calendar_ready = False
self.calendar_loaded = False
self.overrides_loaded = False
self.event_overrides = {}
self.event_sensors = []
self.code_generator = config.get(CONF_CODE_GENERATION, DEFAULT_CODE_GENERATION)
Expand Down Expand Up @@ -534,7 +536,9 @@ async def update_event_overrides(
_LOGGER.debug("event_overrides: '%s'", self.event_overrides)
if len(self.event_overrides) == self.max_events:
_LOGGER.debug("max_events reached, flagging as ready")
self.calendar_ready = True
self.overrides_loaded = True
if self.calendar_loaded:
self.calendar_ready = True
else:
_LOGGER.debug(
"max_events not reached yet, calendar_ready is '%s'",
Expand Down Expand Up @@ -708,7 +712,12 @@ async def _refresh_calendar(self):
event_list, start_of_events, end_of_events
)

self.calendar_loaded = True

if self.lockname is None:
self.overrides_loaded = True

if self.overrides_loaded:
self.calendar_ready = True

if len(self.calendar) > 0:
Expand Down
4 changes: 4 additions & 0 deletions custom_components/rental_control/sensors/calsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ async def async_update(self):

await self.rental_control_events.update()

# Calendar is not ready, no reason to continue processing
if not self.rental_control_events.calendar_ready:
return

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 1c888da

Please sign in to comment.