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

Use installed_version for the update entity #2584

Merged
merged 5 commits into from
Apr 1, 2022
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: 1 addition & 1 deletion .github/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- "--py38-plus"

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
stages: [manual]
Expand Down
49 changes: 34 additions & 15 deletions custom_components/hacs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def async_setup_entry(hass, _config_entry, async_add_devices):
class HacsRepositoryUpdateEntity(HacsRepositoryEntity, UpdateEntity):
"""Update entities for repositories downloaded with HACS."""

_attr_supported_features = 1
_attr_supported_features = 1 | 16

@property
def name(self) -> str | None:
Expand All @@ -34,18 +34,6 @@ def latest_version(self) -> str:
"""Return latest version of the entity."""
return self.repository.display_available_version

@property
def release_summary(self) -> str | None:
"""Return the release summary."""
if self.repository.pending_restart:
return "🔴 Restart of Home Assistant required 🔴 "
if self.repository.pending_update:
if self.repository.data.category == HacsCategory.INTEGRATION:
return "🟡 You need to restart Home Assistant manually after updating."
if self.repository.data.category == HacsCategory.PLUGIN:
return "🟡 You manually clear the frontend cache after updating."
return None

@property
def release_url(self) -> str:
"""Return the URL of the release page."""
Expand All @@ -54,13 +42,44 @@ def release_url(self) -> str:
return f"https://github.com/{self.repository.data.full_name}/releases/{self.latest_version}"

@property
def current_version(self) -> str:
"""Return latest version of the entity."""
def installed_version(self) -> str:
"""Return downloaded version of the entity."""
return self.repository.display_installed_version

@property
def release_summary(self) -> str | None:
"""Return the release summary."""
if self.repository.pending_restart:
return "<ha-alert alert-type='error'>Restart of Home Assistant required</ha-alert>"
return None

async def async_install(self, version: str | None, backup: bool, **kwargs: Any) -> None:
"""Install an update."""
if self.repository.display_version_or_commit == "version":
self.repository.data.selected_tag = self.latest_version
await self.repository.update_repository(force=True)
await self.repository.async_install()

async def async_release_notes(self) -> str | None:
"""Return the release notes."""
release_notes = ""
if self.repository.pending_restart:
return None

if len(self.repository.releases.objects) > 0:
release = self.repository.releases.objects[0]
release_notes += release.body

if self.repository.pending_update:
if self.repository.data.category == HacsCategory.INTEGRATION:
release_notes += (
"<ha-alert alert-type='warning'>You need to restart"
" Home Assistant manually after updating.</ha-alert>\n\n"
)
if self.repository.data.category == HacsCategory.PLUGIN:
release_notes += (
"<ha-alert alert-type='warning'>You need to manually"
" clear the frontend cache after updating.</ha-alert>\n\n"
)

return release_notes