Skip to content

Commit

Permalink
Always enable category when items are downloaded (#3277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Sep 26, 2023
1 parent e92989a commit d9f9e43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
23 changes: 15 additions & 8 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 "
Expand Down
8 changes: 7 additions & 1 deletion tests/hacsbase/test_hacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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()


Expand Down

0 comments on commit d9f9e43

Please sign in to comment.