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

Store information about releases #2501

Merged
merged 2 commits into from
Feb 9, 2022
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
3 changes: 3 additions & 0 deletions custom_components/hacs/tasks/load_hacs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ async def async_execute(self) -> None:
repository = self.hacs.repositories.get_by_full_name(HacsGitHubRepo.INTEGRATION)
if repository is None:
raise HacsException("Unknown error")

repository.data.installed = True
repository.data.installed_version = self.hacs.integration.version
repository.data.new = False
repository.data.releases = True

self.hacs.repository = repository.repository_object
self.hacs.repositories.mark_default(repository)
except HacsException as exception:
Expand Down
11 changes: 3 additions & 8 deletions custom_components/hacs/tasks/update_downloaded_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.core import HomeAssistant

from ..base import HacsBase
from ..enums import HacsGitHubRepo, HacsStage
from ..enums import HacsStage
from .base import HacsTask


Expand All @@ -25,13 +25,8 @@ async def async_execute(self) -> None:
"""Execute the task."""
self.hacs.log.debug("Starting recurring background task for installed repositories")

for repository in self.hacs.repositories.list_all:
if self.hacs.status.startup and repository.data.full_name == HacsGitHubRepo.INTEGRATION:
continue
if (
repository.data.installed
and repository.data.category in self.hacs.common.categories
):
for repository in self.hacs.repositories.list_downloaded:
if repository.data.category in self.hacs.common.categories:
self.hacs.queue.add(repository.update_repository())

await self.hacs.data.async_write()
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hacs/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async def async_store_repository_data(self, repository: HacsRepository):
"name": repository.data.name,
"new": repository.data.new,
"repository_manifest": repository_manifest,
"releases": repository.data.releases,
"selected_tag": repository.data.selected_tag,
"show_beta": repository.data.show_beta,
"stars": repository.data.stargazers_count,
Expand Down Expand Up @@ -219,6 +220,7 @@ def async_restore_repository(self, entry, repository_data):
repository.data.domain = repository_data.get("domain", None)
repository.data.stargazers_count = repository_data.get("stars", 0)
repository.releases.last_release = repository_data.get("last_release_tag")
repository.data.releases = repository_data.get("releases")
repository.data.hide = repository_data.get("hide", False)
repository.data.installed = repository_data.get("installed", False)
repository.data.new = repository_data.get("new", True)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/utils/default.repositories

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def hass(event_loop, tmpdir):

def exc_handle(loop, context):
"""Handle exceptions by rethrowing them, which will fail the test."""
exceptions.append(context["exception"])
if exception := context.get("exception"):
exceptions.append(exception)
orig_exception_handler(loop, context)

exceptions = []
Expand Down
24 changes: 0 additions & 24 deletions tests/tasks/test_update_downloaded_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,3 @@ async def test_update_downloaded_repositories(hacs: HacsBase, repository: HacsRe
assert hacs.queue.pending_tasks == 0
await task.execute_task()
assert hacs.queue.pending_tasks == 1


@pytest.mark.asyncio
async def test_update_downloaded_repositories_skip_hacs_on_startup(
hacs: HacsBase,
repository: HacsRepository,
):
await hacs.tasks.async_load()
task = hacs.tasks.get("update_downloaded_repositories")

hacs.status.startup = True

repository.data.category = HacsCategory.INTEGRATION
repository.data.installed = True
repository.data.full_name = "hacs/integration"
hacs.repositories.register(repository)

hacs.enable_hacs_category(HacsCategory.INTEGRATION)

assert task

assert hacs.queue.pending_tasks == 0
await task.execute_task()
assert hacs.queue.pending_tasks == 0