Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent inaccessible calendars from deleting #136

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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