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 task schedule loader #2185

Merged
merged 1 commit into from
Aug 28, 2021
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
4 changes: 0 additions & 4 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,13 @@ def disable_hacs(self, reason: HacsDisabledReason) -> None:
"""Disable HACS."""
self.system.disabled = True
self.system.disabled_reason = reason
for task in self.recuring_tasks:
task()
if reason != HacsDisabledReason.REMOVED:
self.log.error("HACS is disabled - %s", reason)

def enable_hacs(self) -> None:
"""Enable HACS."""
self.system.disabled = False
self.system.disabled_reason = None
if self.tasks:
self.tasks.register_scheduled_handlers()
self.log.info("HACS is enabled")

def enable_hacs_category(self, category: HacsCategory):
Expand Down
14 changes: 4 additions & 10 deletions custom_components/hacs/tasks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,16 @@ async def _load_module(module: str):

await asyncio.gather(*[_load_module(task) for task in task_modules])
self.log.info("Loaded %s tasks", len(self.tasks))
self.register_event_handlers()
self.register_scheduled_handlers()

def register_event_handlers(self) -> None:
"""Register event handlers."""
schedule_tasks = len(self.hacs.recuring_tasks) == 0

for task in self.tasks:
if task.events is not None:
for event in task.events:
self.hacs.hass.bus.async_listen_once(event, task.execute_task)

def register_scheduled_handlers(self) -> None:
"""Register event handlers."""
for task in self.hacs.recuring_tasks:
task()
for task in self.tasks:
if task.schedule is not None:
if task.schedule is not None and schedule_tasks:
self.log.debug("Scheduling the %s task to run every %s", task.slug, task.schedule)
self.hacs.recuring_tasks.append(
self.hacs.hass.helpers.event.async_track_time_interval(
task.execute_task, task.schedule
Expand Down