Skip to content

Commit

Permalink
Remove mixin module (#2386)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 26, 2021
1 parent bba4e78 commit 46bed88
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 35 deletions.
13 changes: 0 additions & 13 deletions custom_components/hacs/mixin.py

This file was deleted.

11 changes: 5 additions & 6 deletions custom_components/hacs/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

from ..base import HacsBase
from ..enums import HacsStage
from ..mixin import LogMixin


class HacsTask(LogMixin):
class HacsTask:
"""Hacs task base."""

events: list[str] | None = None
Expand All @@ -38,11 +37,11 @@ async def execute_task(self, *_, **__) -> None:
"""Execute the task defined in subclass."""
if not self._can_run_disabled and self.hacs.system.disabled:
self.task_logger(
self.log.debug,
self.hacs.log.debug,
f"Skipping task, HACS is disabled {self.hacs.system.disabled_reason}",
)
return
self.task_logger(self.log.debug, "Executing task")
self.task_logger(self.hacs.log.debug, "Executing task")
start_time = monotonic()

try:
Expand All @@ -51,9 +50,9 @@ async def execute_task(self, *_, **__) -> None:
elif task := getattr(self, "async_execute", None):
await task() # pylint: disable=not-callable
except BaseException as exception: # pylint: disable=broad-except
self.task_logger(self.log.error, f"failed: {exception}")
self.task_logger(self.hacs.log.error, f"failed: {exception}")

else:
self.log.debug(
self.hacs.log.debug(
"HacsTask<%s> took %.3f seconds to complete", self.slug, monotonic() - start_time
)
4 changes: 2 additions & 2 deletions custom_components/hacs/tasks/check_constrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def execute(self) -> None:
):
if os.path.exists(location):
self.task_logger(
self.log.critical,
self.hacs.log.critical,
"This cannot be used with custom_updater. "
f"To use this you need to remove custom_updater form {location}",
)
Expand All @@ -42,7 +42,7 @@ def execute(self) -> None:
MINIMUM_HA_VERSION,
):
self.task_logger(
self.log.critical,
self.hacs.log.critical,
f"You need HA version {MINIMUM_HA_VERSION} or newer to use this integration.",
)
self.hacs.disable_hacs(HacsDisabledReason.CONSTRAINS)
8 changes: 4 additions & 4 deletions custom_components/hacs/tasks/check_ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class Task(HacsTask):
async def async_execute(self) -> None:
"""Execute the task."""
if not self.hacs.stage == HacsStage.RUNNING:
self.task_logger(self.log.debug, "HACS is not running")
self.task_logger(self.hacs.log.debug, "HACS is not running")
return
if (
not self.hacs.system.disabled
or self.hacs.system.disabled_reason != HacsDisabledReason.RATE_LIMIT
):
self.task_logger(self.log.debug, "HACS is not ratelimited")
self.task_logger(self.hacs.log.debug, "HACS is not ratelimited")
return

self.task_logger(self.log.debug, "Checking if ratelimit has lifted")
self.task_logger(self.hacs.log.debug, "Checking if ratelimit has lifted")
can_update = await self.hacs.async_can_update()
self.task_logger(self.log.debug, f"Ratelimit indicate we can update {can_update}")
self.task_logger(self.hacs.log.debug, f"Ratelimit indicate we can update {can_update}")
if can_update > 0:
self.hacs.enable_hacs()
2 changes: 1 addition & 1 deletion custom_components/hacs/tasks/clear_old_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def execute(self) -> None:
for storage_file in ("hacs",):
path = f"{self.hacs.core.config_path}/.storage/{storage_file}"
if os.path.isfile(path):
self.task_logger(self.log.info, f"Cleaning up old storage file: {path}")
self.task_logger(self.hacs.log.info, f"Cleaning up old storage file: {path}")
os.remove(path)
4 changes: 2 additions & 2 deletions custom_components/hacs/tasks/load_hacs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ async def async_execute(self) -> None:
except HacsException as exception:
if "403" in f"{exception}":
self.task_logger(
self.log.critical,
self.hacs.log.critical,
"GitHub API is ratelimited, or the token is wrong.",
)
else:
self.task_logger(self.log.critical, f"[{exception}] - Could not load HACS!")
self.task_logger(self.hacs.log.critical, f"[{exception}] - Could not load HACS!")
self.hacs.disable_hacs(HacsDisabledReason.LOAD_HACS)
9 changes: 5 additions & 4 deletions custom_components/hacs/tasks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from homeassistant.core import HomeAssistant

from ..base import HacsBase
from ..mixin import LogMixin
from .base import HacsTask


class HacsTaskManager(LogMixin):
class HacsTaskManager:
"""Hacs task manager."""

def __init__(self, hacs: HacsBase, hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -41,7 +40,7 @@ async def _load_module(module: str):
self.__tasks[task.slug] = task

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

schedule_tasks = len(self.hacs.recuring_tasks) == 0

Expand All @@ -51,7 +50,9 @@ async def _load_module(module: str):
self.hass.bus.async_listen_once(event, task.execute_task)

if task.schedule is not None and schedule_tasks:
self.log.debug("Scheduling HacsTask<%s> to run every %s", task.slug, task.schedule)
self.hacs.log.debug(
"Scheduling HacsTask<%s> 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
4 changes: 2 additions & 2 deletions custom_components/hacs/tasks/setup_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def async_execute(self) -> None:
# Register frontend
if self.hacs.configuration.frontend_repo_url:
self.task_logger(
self.log.warning,
self.hacs.log.warning,
"Frontend development mode enabled. Do not run in production!",
)
self.hass.http.register_view(HacsFrontendDev())
Expand All @@ -55,7 +55,7 @@ async def async_execute(self) -> None:
# Register www/community for all other files
use_cache = self.hacs.core.lovelace_mode == "storage"
self.task_logger(
self.log.info,
self.hacs.log.info,
f"{self.hacs.core.lovelace_mode} mode, cache for /hacsfiles/: {use_cache}",
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/tasks/verify_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class Task(HacsTask):
async def async_execute(self) -> None:
"""Execute the task."""
can_update = await self.hacs.async_can_update()
self.task_logger(self.log.debug, f"Can update {can_update} repositories")
self.task_logger(self.hacs.log.debug, f"Can update {can_update} repositories")

0 comments on commit 46bed88

Please sign in to comment.