Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always enable category when items are downloaded #3277

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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