Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remvoe RepositoryHelperProperties #2362

Merged
merged 1 commit into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions custom_components/hacs/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
HacsHelperMethods,
RepositoryHelperMethods,
)
from custom_components.hacs.helpers.properties import RepositoryHelperProperties


class RepositoryHelpers(
RepositoryHelperMethods,
RepositoryHelperProperties,
):
"""Helper class for repositories"""

Expand Down
42 changes: 40 additions & 2 deletions custom_components/hacs/helpers/classes/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/helpers/functions/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/helpers/methods/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions custom_components/hacs/helpers/properties/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions custom_components/hacs/helpers/properties/can_be_installed.py

This file was deleted.

32 changes: 0 additions & 32 deletions custom_components/hacs/helpers/properties/pending_update.py

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/hacs/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/tasks/setup_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/methods/test_installation_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/repositories/helpers/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions tests/repositories/test_can_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions tests/repositories/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -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