Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions custom_components/hacs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ async def async_install(self, version: str | None, backup: bool, **kwargs: Any)
except HacsException as exception:
raise HomeAssistantError(exception) from exception

# Persist the new installed state, otherwise a restart of
# Home Assistant before the next write reverts it.
await self.hacs.data.async_write()

async def async_release_notes(self) -> str | None:
"""Return the release notes."""
if self.repository.pending_restart:
Expand Down
42 changes: 42 additions & 0 deletions tests/repositories/test_update_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from custom_components.hacs.const import DOMAIN
from custom_components.hacs.utils.store import async_load_from_store

from tests.common import (
CategoryTestData,
Expand Down Expand Up @@ -93,6 +94,47 @@ async def test_update_repository_websocket(
)


async def test_update_repository_entity_persists_installed_version(
hass: HomeAssistant,
setup_integration: Generator,
):
"""Ensure an install through the update entity is written to storage."""
hacs = get_hacs(hass)
repo = hacs.repositories.get_by_full_name(
"hacs-test-org/integration-basic")

assert repo is not None

repo.data.installed = True
repo.data.installed_version = "1.0.0"

await hass.config_entries.async_reload(hacs.configuration.config_entry.entry_id)
await hass.async_block_till_done()

# Get a new HACS instance after reload
hacs = get_hacs(hass)
repo = hacs.repositories.get_by_full_name(
"hacs-test-org/integration-basic")

er = async_get_entity_registry(hacs.hass)
entity_id = er.async_get_entity_id("update", DOMAIN, repo.data.id)

await hass.services.async_call(
"update",
"install",
service_data={"entity_id": entity_id, "version": "2.0.0"},
blocking=True,
)

stored = await async_load_from_store(hass, "data")
stored_repo = next(
entry
for entry in stored["repositories"]["integration"]
if entry["full_name"] == "hacs-test-org/integration-basic"
)
assert stored_repo["version_installed"] == "2.0.0"


async def test_update_repository_entity_no_manifest(
hass: HomeAssistant,
setup_integration: Generator,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"tests/repositories/test_update_repository.py::test_update_repository_entity_persists_installed_version": {
"https://api.github.com/repos/hacs-test-org/integration-basic": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/branches/main": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/contents/custom_components/example/manifest.json": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/contents/hacs.json": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/git/trees/1.0.0": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
"https://api.github.com/repos/hacs/integration/git/trees/main": 1,
"https://api.github.com/repos/hacs/integration/releases": 1,
"https://data-v2.hacs.xyz/appdaemon/data.json": 1,
"https://data-v2.hacs.xyz/critical/data.json": 1,
"https://data-v2.hacs.xyz/integration/data.json": 1,
"https://data-v2.hacs.xyz/plugin/data.json": 1,
"https://data-v2.hacs.xyz/python_script/data.json": 1,
"https://data-v2.hacs.xyz/removed/data.json": 1,
"https://data-v2.hacs.xyz/template/data.json": 1,
"https://data-v2.hacs.xyz/theme/data.json": 1,
"https://github.com/hacs-test-org/integration-basic/archive/refs/tags/2.0.0.zip": 1,
"https://raw.githubusercontent.com/hacs-test-org/integration-basic/1.0.0/README.md": 1,
"https://raw.githubusercontent.com/hacs-test-org/integration-basic/2.0.0/hacs.json": 1
}
}
Comment thread
frenck marked this conversation as resolved.
Outdated
Loading