diff --git a/custom_components/hacs/tasks/base.py b/custom_components/hacs/tasks/base.py index 87128c737a0..ae0835d5dcd 100644 --- a/custom_components/hacs/tasks/base.py +++ b/custom_components/hacs/tasks/base.py @@ -39,13 +39,12 @@ def task_logger(self, handler: Handler, msg: str) -> None: async def execute_task(self, *_, **__) -> None: """Execute the task defined in subclass.""" if not self._can_run_disabled and self.hacs.system.disabled: - self.log.warning( - "HacsTask<%s> Skipping task, HACS is disabled - %s", - self.slug, - self.hacs.system.disabled_reason, + self.task_logger( + self.log.debug, + f"Skipping task, HACS is disabled {self.hacs.system.disabled_reason}", ) return - self.log.info("HacsTask<%s> Executing task", self.slug) + self.task_logger(self.log.debug, "Executing task") start_time = timer() try: @@ -54,11 +53,10 @@ 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.log.error("HacsTask<%s> failed: %s", self.slug, exception) + self.task_logger(self.log.error, f"failed: {exception}") else: - self.log.debug( - "HacsTask<%s> took " "%.2f seconds to complete", - self.slug, - timer() - start_time, + self.task_logger( + self.log.debug, + f"took {str(timer() - start_time)[:5]} seconds to complete", ) diff --git a/custom_components/hacs/tasks/check_ratelimit.py b/custom_components/hacs/tasks/check_ratelimit.py index 1a074b5bca2..ad67899c388 100644 --- a/custom_components/hacs/tasks/check_ratelimit.py +++ b/custom_components/hacs/tasks/check_ratelimit.py @@ -19,7 +19,7 @@ class Task(HacsTask): """ "Hacs task base.""" _can_run_disabled = True - schedule = timedelta(minutes=15) + schedule = timedelta(hours=1) async def async_execute(self) -> None: """Execute the task.""" diff --git a/custom_components/hacs/tasks/hello_world.py b/custom_components/hacs/tasks/hello_world.py deleted file mode 100644 index 6d70e9244f0..00000000000 --- a/custom_components/hacs/tasks/hello_world.py +++ /dev/null @@ -1,24 +0,0 @@ -""""Hacs base setup task.""" -from __future__ import annotations - -from datetime import timedelta - -from homeassistant.core import HomeAssistant - -from ..base import HacsBase -from .base import HacsTask - - -async def async_setup_task(hacs: HacsBase, hass: HomeAssistant) -> Task: - """Set up this task.""" - return Task(hacs=hacs, hass=hass) - - -class Task(HacsTask): - """ "Hacs task base.""" - - schedule = timedelta(weeks=52) - - def execute(self) -> None: - """Execute the task.""" - self.task_logger(self.log.debug, "Hello World!") diff --git a/tests/tasks/test_hello_world.py b/tests/tasks/test_hello_world.py deleted file mode 100644 index 23637a11ba1..00000000000 --- a/tests/tasks/test_hello_world.py +++ /dev/null @@ -1,44 +0,0 @@ -# pylint: disable=missing-function-docstring,missing-module-docstring, protected-access -from unittest.mock import patch - -import pytest - -from custom_components.hacs.base import HacsBase - - -@pytest.mark.asyncio -async def test_hello_world(hacs: HacsBase, caplog: pytest.LogCaptureFixture): - await hacs.tasks.async_load() - task = hacs.tasks.get("hello_world") - - assert task - - await task.execute_task() - assert "Hello World!" in caplog.text - - -@pytest.mark.asyncio -async def test_hello_world_exception(hacs: HacsBase, caplog: pytest.LogCaptureFixture): - await hacs.tasks.async_load() - task = hacs.tasks.get("hello_world") - - assert task - - with patch( - "custom_components.hacs.tasks.hello_world.Task.execute", side_effect=Exception("lore_ipsum") - ): - await task.execute_task() - assert "HacsTask failed: lore_ipsum" in caplog.text - - -@pytest.mark.asyncio -async def test_hello_world_disabled(hacs: HacsBase, caplog: pytest.LogCaptureFixture): - await hacs.tasks.async_load() - task = hacs.tasks.get("hello_world") - - assert task - - hacs.system.disabled_reason = "lorem_ipsum" - - await task.execute_task() - assert "HacsTask Skipping task, HACS is disabled - lorem_ipsum" in caplog.text