diff --git a/custom_components/hacs/helpers/functions/misc.py b/custom_components/hacs/helpers/functions/misc.py index e31977b8dd7..bf056a6d9ae 100644 --- a/custom_components/hacs/helpers/functions/misc.py +++ b/custom_components/hacs/helpers/functions/misc.py @@ -22,11 +22,6 @@ def get_repository_name(repository) -> str: return repository.data.full_name.split("/")[-1].replace("-", " ").replace("_", " ").title() -def version_left_higher_then_right(left: str, right: str) -> bool: - """Return a bool if source is newer than target, will also be true if identical.""" - return version.version_left_higher_then_right(left, right) - - def extract_repository_from_url(url: str) -> str or None: """Extract the owner/repo part form a URL.""" match = re.match(RE_REPOSITORY, url) diff --git a/custom_components/hacs/helpers/properties/can_be_installed.py b/custom_components/hacs/helpers/properties/can_be_installed.py index 6ec5df62992..716be3deb95 100644 --- a/custom_components/hacs/helpers/properties/can_be_installed.py +++ b/custom_components/hacs/helpers/properties/can_be_installed.py @@ -1,7 +1,7 @@ # pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member from abc import ABC -from custom_components.hacs.helpers.functions.misc import version_left_higher_then_right +from custom_components.hacs.utils.version import version_left_higher_or_equal_then_right class RepositoryPropertyCanBeInstalled(ABC): @@ -9,7 +9,7 @@ class RepositoryPropertyCanBeInstalled(ABC): def can_be_installed(self) -> bool: if self.data.homeassistant is not None: if self.data.releases: - if not version_left_higher_then_right( + if not version_left_higher_or_equal_then_right( self.hacs.core.ha_version, self.data.homeassistant ): return False diff --git a/custom_components/hacs/tasks/check_constrains.py b/custom_components/hacs/tasks/check_constrains.py index 5745cbb4ef6..a2f3e3cbf91 100644 --- a/custom_components/hacs/tasks/check_constrains.py +++ b/custom_components/hacs/tasks/check_constrains.py @@ -8,7 +8,7 @@ from ..base import HacsBase from ..const import MINIMUM_HA_VERSION from ..enums import HacsDisabledReason, HacsStage -from ..utils.version import version_left_higher_then_right +from ..utils.version import version_left_higher_or_equal_then_right from .base import HacsTask @@ -37,7 +37,9 @@ def execute(self) -> None: self.hacs.disable_hacs(HacsDisabledReason.CONSTRAINS) - if not version_left_higher_then_right(self.hacs.core.ha_version, MINIMUM_HA_VERSION): + if not version_left_higher_or_equal_then_right( + self.hacs.core.ha_version, MINIMUM_HA_VERSION + ): self.task_logger( self.log.critical, f"You need HA version {MINIMUM_HA_VERSION} or newer to use this integration.", diff --git a/custom_components/hacs/utils/version.py b/custom_components/hacs/utils/version.py index 36e54f6607e..c3baa6f1b85 100644 --- a/custom_components/hacs/utils/version.py +++ b/custom_components/hacs/utils/version.py @@ -10,6 +10,16 @@ def version_left_higher_then_right(left: str, right: str) -> bool: """Return a bool if source is newer than target, will also be true if identical.""" try: - return AwesomeVersion(left) >= AwesomeVersion(right) + return AwesomeVersion(left) > AwesomeVersion(right) + except (AwesomeVersionException, AttributeError): + return False + + +def version_left_higher_or_equal_then_right(left: str, right: str) -> bool: + """Return a bool if source is newer than target, will also be true if identical.""" + if left == right: + return True + try: + return version_left_higher_then_right(left, right) except (AwesomeVersionException, AttributeError): return False diff --git a/tests/helpers/misc/test_version_is_newer_than_version.py b/tests/helpers/misc/test_version_is_newer_than_version.py index bcc8bfce670..a14f51825fb 100644 --- a/tests/helpers/misc/test_version_is_newer_than_version.py +++ b/tests/helpers/misc/test_version_is_newer_than_version.py @@ -1,28 +1,28 @@ -"""Helpers: Misc: version_left_higher_then_right.""" +"""Helpers: Misc: version_left_higher_or_equal_then_right.""" # pylint: disable=missing-docstring -from custom_components.hacs.helpers.functions.misc import version_left_higher_then_right +from custom_components.hacs.utils.version import version_left_higher_or_equal_then_right def test_basic(): - assert version_left_higher_then_right("1.0.0", "0.9.9") - assert version_left_higher_then_right("1", "0.9.9") - assert version_left_higher_then_right("1.1", "0.9.9") - assert version_left_higher_then_right("0.10.0", "0.9.9") - assert not version_left_higher_then_right("0.0.10", "0.9.9") - assert not version_left_higher_then_right("0.9.0", "0.9.9") - assert version_left_higher_then_right("1.0.0", "1.0.0") + assert version_left_higher_or_equal_then_right("1.0.0", "0.9.9") + assert version_left_higher_or_equal_then_right("1", "0.9.9") + assert version_left_higher_or_equal_then_right("1.1", "0.9.9") + assert version_left_higher_or_equal_then_right("0.10.0", "0.9.9") + assert not version_left_higher_or_equal_then_right("0.0.10", "0.9.9") + assert not version_left_higher_or_equal_then_right("0.9.0", "0.9.9") + assert version_left_higher_or_equal_then_right("1.0.0", "1.0.0") def test_beta(): - assert version_left_higher_then_right("1.0.0b1", "1.0.0b0") - assert not version_left_higher_then_right("1.0.0b1", "1.0.0") - assert version_left_higher_then_right("1.0.0", "1.0.0b1") + assert version_left_higher_or_equal_then_right("1.0.0b1", "1.0.0b0") + assert not version_left_higher_or_equal_then_right("1.0.0b1", "1.0.0") + assert version_left_higher_or_equal_then_right("1.0.0", "1.0.0b1") def test_wierd_stuff(): - assert version_left_higher_then_right("1.0.0rc1", "1.0.0b1") - assert not version_left_higher_then_right("1.0.0a1", "1.0.0b1") - assert version_left_higher_then_right("1.0.0", "1.0.0a0") - assert version_left_higher_then_right("1.0.0", "1.0.0b0") - assert version_left_higher_then_right("1.0.0", "1.0.0rc0") - assert not version_left_higher_then_right("0", "1.0.0rc0") + assert version_left_higher_or_equal_then_right("1.0.0rc1", "1.0.0b1") + assert not version_left_higher_or_equal_then_right("1.0.0a1", "1.0.0b1") + assert version_left_higher_or_equal_then_right("1.0.0", "1.0.0a0") + assert version_left_higher_or_equal_then_right("1.0.0", "1.0.0b0") + assert version_left_higher_or_equal_then_right("1.0.0", "1.0.0rc0") + assert not version_left_higher_or_equal_then_right("0", "1.0.0rc0")