diff --git a/custom_components/hacs/repositories/base.py b/custom_components/hacs/repositories/base.py index a3d1807dc43..aa43fd7d32f 100644 --- a/custom_components/hacs/repositories/base.py +++ b/custom_components/hacs/repositories/base.py @@ -413,7 +413,10 @@ def pending_update(self) -> bool: if self.data.installed_commit != self.data.last_commit: return True return False - if self.display_version_or_commit == "version": + if ( + self.display_version_or_commit == "version" + and self.data.installed_version is not None + ): if ( result := version_left_higher_then_right( self.display_available_version, diff --git a/tests/repositories/helpers/test_properties.py b/tests/repositories/helpers/test_properties.py index e8e0216ad7c..5d9128f1e89 100644 --- a/tests/repositories/helpers/test_properties.py +++ b/tests/repositories/helpers/test_properties.py @@ -1,6 +1,7 @@ """HACS Repository Helper properties.""" # pylint: disable=missing-docstring from awesomeversion import AwesomeVersion +import pytest from custom_components.hacs.repositories.base import HacsRepository @@ -21,8 +22,33 @@ def test_repository_helpers_properties_pending_update(hacs): repository.data.installed = True repository.data.default_branch = "main" repository.data.selected_tag = "main" + repository.data.releases = True + repository.data.last_version = "0.2.0" assert not repository.pending_update repository.data.installed_commit = "1" repository.data.last_commit = "2" assert repository.pending_update + + +@pytest.mark.parametrize( + ("installed_version", "installed_commit", "pending_update"), + [ + (None, "3730b11", True), + (None, "1234567", True), + (None, "abcdef0", True), + ("0.1.0", "3730b11", True), + ("0.2.0", "3730b11", False), + ("0.3.0", "3730b11", False), + ], +) +def test_pending_update_with_releases(hacs, installed_version, installed_commit, pending_update): + """Compare release versions without treating an installed commit as a version.""" + repository = HacsRepository(hacs) + repository.data.installed = True + repository.data.installed_version = installed_version + repository.data.installed_commit = installed_commit + repository.data.releases = True + repository.data.last_version = "0.2.0" + + assert repository.pending_update is pending_update diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-1-0-3730b11-true.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-1-0-3730b11-true.json new file mode 100644 index 00000000000..dc060a6c876 --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-1-0-3730b11-true.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[0.1.0-3730b11-True]": { + "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 + } +} \ No newline at end of file diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-2-0-3730b11-false.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-2-0-3730b11-false.json new file mode 100644 index 00000000000..09928dde4d6 --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-2-0-3730b11-false.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[0.2.0-3730b11-False]": { + "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 + } +} \ No newline at end of file diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-3-0-3730b11-false.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-3-0-3730b11-false.json new file mode 100644 index 00000000000..63531e6f827 --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-0-3-0-3730b11-false.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[0.3.0-3730b11-False]": { + "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 + } +} \ No newline at end of file diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-1234567-true.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-1234567-true.json new file mode 100644 index 00000000000..af9d5c5516c --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-1234567-true.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[None-1234567-True]": { + "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 + } +} \ No newline at end of file diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-3730b11-true.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-3730b11-true.json new file mode 100644 index 00000000000..8e8a89ef100 --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-3730b11-true.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[None-3730b11-True]": { + "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 + } +} \ No newline at end of file diff --git a/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-abcdef0-true.json b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-abcdef0-true.json new file mode 100644 index 00000000000..3216dbc9591 --- /dev/null +++ b/tests/snapshots/api-usage/tests/repositories/helpers/test_propertiestest-pending-update-with-releases-none-abcdef0-true.json @@ -0,0 +1,9 @@ +{ + "tests/repositories/helpers/test_properties.py::test_pending_update_with_releases[None-abcdef0-True]": { + "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 + } +} \ No newline at end of file