diff --git a/supervisor/jobs/decorator.py b/supervisor/jobs/decorator.py index 0dc41d127..b6a5b2970 100644 --- a/supervisor/jobs/decorator.py +++ b/supervisor/jobs/decorator.py @@ -18,7 +18,8 @@ class JobCondition(str, Enum): FREE_SPACE = "free_space" HEALTHY = "healthy" - INTERNET = "internet" + INTERNET_SYSTEM = "internet_system" + INTERNET_HOST = "internet_host" class Job: @@ -95,21 +96,31 @@ class Job: ) return False - if JobCondition.INTERNET in self.conditions: + if any( + internet in self.conditions + for internet in ( + JobCondition.INTERNET_SYSTEM, + JobCondition.INTERNET_HOST, + ) + ): if self._coresys.core.state not in ( CoreState.SETUP, CoreState.RUNNING, ): return True - if not self._coresys.supervisor.connectivity: + if ( + JobCondition.INTERNET_SYSTEM in self.conditions + and not self._coresys.supervisor.connectivity + ): _LOGGER.warning( "'%s' blocked from execution, no supervisor internet connection", self._method.__qualname__, ) return False elif ( - self._coresys.host.network.connectivity is not None + JobCondition.INTERNET_HOST in self.conditions + and self._coresys.host.network.connectivity is not None and not self._coresys.host.network.connectivity ): _LOGGER.warning( diff --git a/supervisor/misc/tasks.py b/supervisor/misc/tasks.py index 20249dfb8..040476a32 100644 --- a/supervisor/misc/tasks.py +++ b/supervisor/misc/tasks.py @@ -120,7 +120,13 @@ class Tasks(CoreSysAttributes): _LOGGER.info("All core tasks are scheduled") - @Job(conditions=[JobCondition.HEALTHY, JobCondition.FREE_SPACE]) + @Job( + conditions=[ + JobCondition.HEALTHY, + JobCondition.FREE_SPACE, + JobCondition.INTERNET_HOST, + ] + ) async def _update_addons(self): """Check if an update is available for an Add-on and update it.""" for addon in self.sys_addons.all: @@ -144,7 +150,7 @@ class Tasks(CoreSysAttributes): except AddonsError: _LOGGER.error("Can't auto update Add-on %s", addon.slug) - @Job(conditions=[JobCondition.FREE_SPACE]) + @Job(conditions=[JobCondition.FREE_SPACE, JobCondition.INTERNET_HOST]) async def _update_supervisor(self): """Check and run update of Supervisor Supervisor.""" if not self.sys_supervisor.need_update: diff --git a/supervisor/store/__init__.py b/supervisor/store/__init__.py index b513be5fc..2687387e4 100644 --- a/supervisor/store/__init__.py +++ b/supervisor/store/__init__.py @@ -56,7 +56,7 @@ class StoreManager(CoreSysAttributes): await self.load() self._read_addons() - @Job(conditions=[JobCondition.INTERNET, JobCondition.HEALTHY]) + @Job(conditions=[JobCondition.INTERNET_SYSTEM, JobCondition.HEALTHY]) async def update_repositories(self, list_repositories): """Add a new custom repository.""" job = self.sys_jobs.get_job("storemanager_update_repositories") diff --git a/supervisor/updater.py b/supervisor/updater.py index 61790d125..75dbac7e2 100644 --- a/supervisor/updater.py +++ b/supervisor/updater.py @@ -159,7 +159,7 @@ class Updater(JsonConfig, CoreSysAttributes): self._data[ATTR_CHANNEL] = value @AsyncThrottle(timedelta(seconds=30)) - @Job(conditions=[JobCondition.INTERNET]) + @Job(conditions=[JobCondition.INTERNET_SYSTEM]) async def fetch_data(self): """Fetch current versions from Github. diff --git a/tests/jobs/test_job_decorator.py b/tests/jobs/test_job_decorator.py index 152ff39cf..26a2f1b5d 100644 --- a/tests/jobs/test_job_decorator.py +++ b/tests/jobs/test_job_decorator.py @@ -44,8 +44,13 @@ async def test_internet(coresys: CoreSys): """Initialize the test class.""" self.coresys = coresys - @Job(conditions=[JobCondition.INTERNET]) - async def execute(self): + @Job(conditions=[JobCondition.INTERNET_HOST]) + async def execute_host(self): + """Execute the class method.""" + return True + + @Job(conditions=[JobCondition.INTERNET_SYSTEM]) + async def execute_system(self): """Execute the class method.""" return True @@ -53,19 +58,23 @@ async def test_internet(coresys: CoreSys): coresys.host.network._connectivity = True coresys.supervisor._connectivity = True - assert await test.execute() + assert await test.execute_host() + assert await test.execute_system() coresys.host.network._connectivity = True coresys.supervisor._connectivity = False - assert not await test.execute() + assert await test.execute_host() + assert not await test.execute_system() coresys.host.network._connectivity = None coresys.supervisor._connectivity = True - assert await test.execute() + assert await test.execute_host() + assert await test.execute_system() coresys.host.network._connectivity = False coresys.supervisor._connectivity = True - assert not await test.execute() + assert not await test.execute_host() + assert await test.execute_system() async def test_free_space(coresys: CoreSys): @@ -101,7 +110,7 @@ async def test_internet_connectivity_with_core_state(coresys: CoreSys): """Initialize the test class.""" self.coresys = coresys - @Job(conditions=[JobCondition.INTERNET]) + @Job(conditions=[JobCondition.INTERNET_SYSTEM, JobCondition.INTERNET_HOST]) async def execute(self): """Execute the class method.""" return True