diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index f11bc033fa9..1fb205eaa51 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -217,6 +217,13 @@ def list_downloaded(self) -> list[HacsRepository]: """Return a list of downloaded repositories.""" return [repo for repo in self._repositories if repo.data.installed] + def category_downloaded(self, category: HacsCategory) -> bool: + """Check if a given category has been downloaded.""" + for repository in self.list_downloaded: + if repository.data.category == category: + return True + return False + def register(self, repository: HacsRepository, default: bool = False) -> None: """Register a repository.""" repo_id = str(repository.data.id) @@ -766,21 +773,21 @@ def set_active_categories(self) -> None: if self.configuration.experimental and self.core.ha_version >= "2023.4.0b0": self.enable_hacs_category(HacsCategory.TEMPLATE) - if HacsCategory.PYTHON_SCRIPT in self.hass.config.components: + if ( + HacsCategory.PYTHON_SCRIPT in self.hass.config.components + or self.repositories.category_downloaded(HacsCategory.PYTHON_SCRIPT) + ): self.enable_hacs_category(HacsCategory.PYTHON_SCRIPT) - if self.hass.services.has_service("frontend", "reload_themes"): + if self.hass.services.has_service( + "frontend", "reload_themes" + ) or self.repositories.category_downloaded(HacsCategory.THEME): self.enable_hacs_category(HacsCategory.THEME) if self.configuration.appdaemon: self.enable_hacs_category(HacsCategory.APPDAEMON) if self.configuration.netdaemon: - downloaded_netdaemon = [ - x - for x in self.repositories.list_downloaded - if x.data.category == HacsCategory.NETDAEMON - ] - if len(downloaded_netdaemon) != 0: + if self.repositories.category_downloaded(HacsCategory.NETDAEMON): self.log.warning( "NetDaemon in HACS is deprectaded. It will stop working in the future. " "Please remove all your current NetDaemon repositories from HACS " diff --git a/tests/hacsbase/test_hacs.py b/tests/hacsbase/test_hacs.py index 4c6b64e490e..c2972d0c09b 100644 --- a/tests/hacsbase/test_hacs.py +++ b/tests/hacsbase/test_hacs.py @@ -2,7 +2,7 @@ import pytest from custom_components.hacs.base import HacsRepositories -from custom_components.hacs.enums import HacsStage +from custom_components.hacs.enums import HacsCategory, HacsStage @pytest.mark.asyncio @@ -13,6 +13,8 @@ async def test_hacs(hacs, repository, tmpdir): assert hacs.repositories.get_by_id(None) is None repository.data.id = "1337" + repository.data.category = "integration" + repository.data.installed = True hacs.repositories.register(repository) assert hacs.repositories.get_by_id("1337").data.full_name == "test/test" @@ -25,6 +27,10 @@ async def test_hacs(hacs, repository, tmpdir): assert hacs.repositories.get_by_full_name("test/test").data.id == "1337" assert hacs.repositories.is_registered(repository_id="1337") + assert hacs.repositories.category_downloaded(category=HacsCategory.INTEGRATION) + for category in [x for x in list(HacsCategory) if x != HacsCategory.INTEGRATION]: + assert not hacs.repositories.category_downloaded(category=category) + await hacs.async_prosess_queue()