From eafa1f9c60eb00e30dc5ad16585e5fba7b733318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sun, 26 Dec 2021 12:57:58 +0100 Subject: [PATCH] Move clear to load repos (#2390) --- custom_components/hacs/base.py | 40 ++++++++++++++++------------------ tests/hacsbase/test_hacs.py | 1 - 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index e25ffaf8338..e74480f8b9a 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -567,7 +567,6 @@ async def startup_tasks(self, _event=None) -> None: await self.handle_critical_repositories_startup() await self.async_load_default_repositories() - await self.clear_out_removed_repositories() self.recuring_tasks.append( self.hass.helpers.event.async_track_time_interval( @@ -699,34 +698,15 @@ async def recurring_tasks_all(self, _notarealarg=None) -> None: self.queue.add(self.async_semaphore_wrapper(repository.common_update)) await self.async_load_default_repositories() - await self.clear_out_removed_repositories() self.status.background_task = False await self.data.async_write() self.hass.bus.async_fire("hacs/status", {}) self.hass.bus.async_fire("hacs/repository", {"action": "reload"}) self.log.debug("Recurring background task for all repositories done") - async def clear_out_removed_repositories(self) -> None: - """Clear out blaclisted repositories.""" - need_to_save = False - for removed in self.repositories.list_removed: - repository = self.repositories.get_by_full_name(removed.repository) - if repository is not None: - if repository.data.installed and removed.removal_type != "critical": - self.log.warning( - f"You have {repository.data.full_name} installed with HACS " - + "this repository has been removed, please consider removing it. " - + f"Removal reason ({removed.removal_type})" - ) - else: - need_to_save = True - repository.remove() - - if need_to_save: - await self.data.async_write() - async def async_load_default_repositories(self) -> None: """Load known repositories.""" + need_to_save = False self.log.info("Loading known repositories") for item in await self.async_github_get_hacs_default_file(HacsCategory.REMOVED): @@ -739,6 +719,24 @@ async def async_load_default_repositories(self) -> None: if queue_task := self.tasks.get("prosess_queue"): await queue_task.execute_task() + for removed in self.repositories.list_removed: + if (repository := self.repositories.get_by_full_name(removed.repository)) is None: + continue + if repository.data.installed and removed.removal_type != "critical": + self.log.warning( + "You have '%s' installed with HACS " + "this repository has been removed from HACS, please consider removing it. " + "Removal reason (%s)", + repository.data.full_name, + removed.reason, + ) + else: + need_to_save = True + repository.remove() + + if need_to_save: + await self.data.async_write() + async def async_get_category_repositories(self, category: HacsCategory) -> None: """Get repositories from category.""" repositories = await self.async_github_get_hacs_default_file(category) diff --git a/tests/hacsbase/test_hacs.py b/tests/hacsbase/test_hacs.py index 5a69da0883e..31708ae1f3c 100644 --- a/tests/hacsbase/test_hacs.py +++ b/tests/hacsbase/test_hacs.py @@ -27,7 +27,6 @@ async def test_hacs(hacs, repository, tmpdir): if queue_task := hacs.tasks.get("prosess_queue"): await queue_task.execute_task() - await hacs.clear_out_removed_repositories() @pytest.mark.asyncio