Skip to content

Commit

Permalink
Use installed_version for the update entity (#2584)
Browse files Browse the repository at this point in the history
* Use installed_version for the update entity

* bump black
  • Loading branch information
ludeeus committed Apr 1, 2022
1 parent 8c6b3fd commit 69972a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
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

0 comments on commit 69972a5

Please sign in to comment.