Skip to content

Commit

Permalink
No update available if update cannot be installed on system
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 committed Jun 12, 2024
1 parent b684c86 commit b7c53d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions supervisor/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,13 @@ def version(self) -> str | None:
@property
def need_update(self) -> bool:
"""Return True if an update is available."""
if self.is_detached:
if self.is_detached or self.version == self.latest_version:
return False
return self.version != self.latest_version

with suppress(AddonsNotSupportedError):
self._validate_availability(self.data_store)
return True
return False

@property
def dns(self) -> list[str]:
Expand Down
36 changes: 36 additions & 0 deletions tests/api/test_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from unittest.mock import MagicMock, PropertyMock, patch

from aiohttp.test_utils import TestClient
from awesomeversion import AwesomeVersion
import pytest

from supervisor.addons.addon import Addon
from supervisor.addons.build import AddonBuild
Expand Down Expand Up @@ -285,3 +287,37 @@ async def test_api_addon_uninstall_remove_config(
assert resp.status == 200
assert not coresys.addons.get("local_example", local_only=True)
assert not test_folder.exists()


async def test_api_update_available_validates_version(
api_client: TestClient,
coresys: CoreSys,
install_addon_example: Addon,
caplog: pytest.LogCaptureFixture,
tmp_supervisor_data,
path_extern,
):
"""Test update available field is only true if user can update to latest version."""
install_addon_example.data["ingress"] = False
install_addon_example.data_store["version"] = "1.3.0"
caplog.clear()

resp = await api_client.get("/addons/local_example/info")
assert resp.status == 200
result = await resp.json()
assert result["data"]["version"] == "1.2.0"
assert result["data"]["version_latest"] == "1.3.0"
assert result["data"]["update_available"] is True

# If new version can't be installed due to HA version, then no update is available
coresys.homeassistant.version = AwesomeVersion("2024.04.0")
install_addon_example.data_store["homeassistant"] = "2024.06.0"

resp = await api_client.get("/addons/local_example/info")
assert resp.status == 200
result = await resp.json()
assert result["data"]["version"] == "1.2.0"
assert result["data"]["version_latest"] == "1.3.0"
assert result["data"]["update_available"] is False

assert "Add-on local_example not supported" not in caplog.text

0 comments on commit b7c53d9

Please sign in to comment.