diff --git a/custom_components/hacs/helpers/__init__.py b/custom_components/hacs/helpers/__init__.py index 8c5755c2768..f3a44a95bd2 100644 --- a/custom_components/hacs/helpers/__init__.py +++ b/custom_components/hacs/helpers/__init__.py @@ -3,12 +3,10 @@ HacsHelperMethods, RepositoryHelperMethods, ) -from custom_components.hacs.helpers.properties import RepositoryHelperProperties class RepositoryHelpers( RepositoryHelperMethods, - RepositoryHelperProperties, ): """Helper class for repositories""" diff --git a/custom_components/hacs/helpers/classes/repository.py b/custom_components/hacs/helpers/classes/repository.py index 8a94987ea05..2f07e2acef9 100644 --- a/custom_components/hacs/helpers/classes/repository.py +++ b/custom_components/hacs/helpers/classes/repository.py @@ -32,7 +32,11 @@ from custom_components.hacs.utils.logger import getLogger from custom_components.hacs.utils.path import is_safe from custom_components.hacs.utils.queue_manager import QueueManager -from custom_components.hacs.utils.version import version_to_download +from custom_components.hacs.utils.version import ( + version_left_higher_or_equal_then_right, + version_to_download, + version_left_higher_then_right, +) class RepositoryVersions: @@ -162,7 +166,7 @@ def display_status(self): status = "new" elif self.pending_restart: status = "pending-restart" - elif self.pending_upgrade: + elif self.pending_update: status = "pending-upgrade" elif self.data.installed: status = "installed" @@ -227,6 +231,40 @@ def main_action(self): } return actions[self.display_status] + @property + def pending_update(self) -> bool: + """Return True if pending update.""" + if not self.can_download: + return False + if self.data.installed: + if self.data.selected_tag is not None: + if self.data.selected_tag == self.data.default_branch: + if self.data.installed_commit != self.data.last_commit: + return True + return False + if self.display_version_or_commit == "version": + if version_left_higher_then_right( + self.display_available_version, + self.display_installed_version, + ): + return True + if self.display_installed_version != self.display_available_version: + return True + + return False + + @property + def can_download(self) -> bool: + """Return True if we can download.""" + if self.data.homeassistant is not None: + if self.data.releases: + if not version_left_higher_or_equal_then_right( + self.hacs.core.ha_version.string, + self.data.homeassistant, + ): + return False + return True + async def common_validate(self, ignore_issues=False): """Common validation steps of the repository.""" await common_validate(self, ignore_issues) diff --git a/custom_components/hacs/helpers/functions/template.py b/custom_components/hacs/helpers/functions/template.py index a7f16edfea5..b8fa4d0c7e0 100644 --- a/custom_components/hacs/helpers/functions/template.py +++ b/custom_components/hacs/helpers/functions/template.py @@ -20,7 +20,7 @@ def render_template(content, context): render = Template(content) render = render.render( installed=context.data.installed, - pending_update=context.pending_upgrade, + pending_update=context.pending_update, prerelease=prerelease, selected_tag=context.data.selected_tag, version_available=context.releases.last_release, diff --git a/custom_components/hacs/helpers/methods/installation.py b/custom_components/hacs/helpers/methods/installation.py index 326a65cd760..f8cf9938bb2 100644 --- a/custom_components/hacs/helpers/methods/installation.py +++ b/custom_components/hacs/helpers/methods/installation.py @@ -54,7 +54,7 @@ async def async_install_repository(repository): raise HacsException("repository.content.path.local is None") repository.validate.errors = [] - if not repository.can_install: + if not repository.can_download: raise HacsException("The version of Home Assistant is not compatible with this version") version = version_to_download(repository) diff --git a/custom_components/hacs/helpers/properties/__init__.py b/custom_components/hacs/helpers/properties/__init__.py deleted file mode 100644 index 7e394d5dbc3..00000000000 --- a/custom_components/hacs/helpers/properties/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member -from custom_components.hacs.helpers.properties.can_be_installed import ( - RepositoryPropertyCanBeInstalled, -) -from custom_components.hacs.helpers.properties.pending_update import ( - RepositoryPropertyPendingUpdate, -) - - -class RepositoryHelperProperties( - RepositoryPropertyPendingUpdate, - RepositoryPropertyCanBeInstalled, -): - pass diff --git a/custom_components/hacs/helpers/properties/can_be_installed.py b/custom_components/hacs/helpers/properties/can_be_installed.py deleted file mode 100644 index d595aa14eb0..00000000000 --- a/custom_components/hacs/helpers/properties/can_be_installed.py +++ /dev/null @@ -1,22 +0,0 @@ -# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member -from abc import ABC - -from custom_components.hacs.utils.version import version_left_higher_or_equal_then_right - - -class RepositoryPropertyCanBeInstalled(ABC): - @property - def can_be_installed(self) -> bool: - if self.data.homeassistant is not None: - if self.data.releases: - if not version_left_higher_or_equal_then_right( - self.hacs.core.ha_version.string, - self.data.homeassistant, - ): - return False - return True - - @property - def can_install(self): - """kept for legacy compatibility""" - return self.can_be_installed diff --git a/custom_components/hacs/helpers/properties/pending_update.py b/custom_components/hacs/helpers/properties/pending_update.py deleted file mode 100644 index 104f520f510..00000000000 --- a/custom_components/hacs/helpers/properties/pending_update.py +++ /dev/null @@ -1,32 +0,0 @@ -# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member -from abc import ABC - -from custom_components.hacs.utils.version import version_left_higher_then_right - - -class RepositoryPropertyPendingUpdate(ABC): - @property - def pending_update(self) -> bool: - if not self.can_install: - return False - if self.data.installed: - if self.data.selected_tag is not None: - if self.data.selected_tag == self.data.default_branch: - if self.data.installed_commit != self.data.last_commit: - return True - return False - if self.display_version_or_commit == "version": - if version_left_higher_then_right( - self.display_available_version, - self.display_installed_version, - ): - return True - if self.display_installed_version != self.display_available_version: - return True - - return False - - @property - def pending_upgrade(self) -> bool: - """kept for legacy compatibility""" - return self.pending_update diff --git a/custom_components/hacs/sensor.py b/custom_components/hacs/sensor.py index 384d403ee20..65e61e663ce 100644 --- a/custom_components/hacs/sensor.py +++ b/custom_components/hacs/sensor.py @@ -72,7 +72,7 @@ def _update(self) -> None: repositories = [ repository for repository in self.hacs.repositories.list_all - if repository.pending_upgrade + if repository.pending_update ] self._attr_native_value = len(repositories) self._attr_extra_state_attributes = { diff --git a/custom_components/hacs/tasks/setup_websocket_api.py b/custom_components/hacs/tasks/setup_websocket_api.py index eab9abaf53a..abb3ed1a1f4 100644 --- a/custom_components/hacs/tasks/setup_websocket_api.py +++ b/custom_components/hacs/tasks/setup_websocket_api.py @@ -143,7 +143,7 @@ async def hacs_repositories(_hass, connection, msg): "authors": repo.data.authors, "available_version": repo.display_available_version, "beta": repo.data.show_beta, - "can_install": repo.can_install, + "can_install": repo.can_download, "category": repo.data.category, "config_flow": repo.data.config_flow, "country": repo.data.country, @@ -169,7 +169,7 @@ async def hacs_repositories(_hass, connection, msg): "main_action": repo.main_action, "name": repo.display_name, "new": repo.data.new, - "pending_upgrade": repo.pending_upgrade, + "pending_upgrade": repo.pending_update, "releases": repo.data.published_tags, "selected_tag": repo.data.selected_tag, "stars": repo.data.stargazers_count, diff --git a/tests/helpers/methods/test_installation_method.py b/tests/helpers/methods/test_installation_method.py index 75ffcfd1038..b7b6457b3e1 100644 --- a/tests/helpers/methods/test_installation_method.py +++ b/tests/helpers/methods/test_installation_method.py @@ -12,6 +12,6 @@ async def test_installation_method(repository): with pytest.raises(HacsException): await repository.async_install() - # repository.can_install = True + # repository.can_download = True await repository._async_post_install() diff --git a/tests/repositories/helpers/test_properties.py b/tests/repositories/helpers/test_properties.py index 364592aa09d..29a87c959d5 100644 --- a/tests/repositories/helpers/test_properties.py +++ b/tests/repositories/helpers/test_properties.py @@ -7,7 +7,7 @@ def test_repository_helpers_properties_can_be_installed(): repository = HacsRepository() - assert repository.can_be_installed + assert repository.can_download def test_repository_helpers_properties_pending_update(): diff --git a/tests/repositories/test_can_install.py b/tests/repositories/test_can_install.py index 4d64d598ec9..51bf77c1a78 100644 --- a/tests/repositories/test_can_install.py +++ b/tests/repositories/test_can_install.py @@ -12,16 +12,16 @@ def test_hacs_can_install(hacs): hacs.core.ha_version = AwesomeVersion("1.0.0") repository.data.homeassistant = "1.0.0b1" - assert repository.can_install + assert repository.can_download hacs.core.ha_version = AwesomeVersion("1.0.0b1") repository.data.homeassistant = "1.0.0" - assert not repository.can_install + assert not repository.can_download hacs.core.ha_version = AwesomeVersion("1.0.0b1") repository.data.homeassistant = "1.0.0b2" - assert not repository.can_install + assert not repository.can_download hacs.core.ha_version = AwesomeVersion("1.0.0") repository.data.homeassistant = "1.0.0" - assert repository.can_install + assert repository.can_download diff --git a/tests/repositories/test_core.py b/tests/repositories/test_core.py index 8bf77531acd..74774720c2a 100644 --- a/tests/repositories/test_core.py +++ b/tests/repositories/test_core.py @@ -20,8 +20,8 @@ def test_hacs_repository_core_mostly_defaults(): assert repository.display_version_or_commit == "commit" assert repository.display_available_version == "" assert repository.display_installed_version == "" - assert repository.can_install - assert not repository.pending_upgrade + assert repository.can_download + assert not repository.pending_update def test_hacs_repository_core_can_install_legacy(): @@ -30,13 +30,13 @@ def test_hacs_repository_core_can_install_legacy(): repository.data.releases = True repository.data.homeassistant = "1.1.0" - assert not repository.can_install + assert not repository.can_download repository.data.homeassistant = "1.0.0" - assert repository.can_install + assert repository.can_download repository.data.homeassistant = "0.1.0" - assert repository.can_install + assert repository.can_download def test_hacs_repository_core_can_install_manifest(): @@ -45,10 +45,10 @@ def test_hacs_repository_core_can_install_manifest(): repository.data.releases = True repository.data.homeassistant = "1.1.0" - assert not repository.can_install + assert not repository.can_download repository.data.homeassistant = "1.0.0" - assert repository.can_install + assert repository.can_download repository.data.homeassistant = "0.1.0" - assert repository.can_install + assert repository.can_download