From 69972a5c181e8e756780342cbdbec1ceaa221732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 1 Apr 2022 21:27:27 +0200 Subject: [PATCH] Use installed_version for the update entity (#2584) * Use installed_version for the update entity * bump black --- .github/pre-commit-config.yaml | 2 +- custom_components/hacs/update.py | 49 ++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/pre-commit-config.yaml b/.github/pre-commit-config.yaml index f6570c19604..d61f256439e 100644 --- a/.github/pre-commit-config.yaml +++ b/.github/pre-commit-config.yaml @@ -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] diff --git a/custom_components/hacs/update.py b/custom_components/hacs/update.py index 1d29d9cb8ff..b1f94d2aa12 100644 --- a/custom_components/hacs/update.py +++ b/custom_components/hacs/update.py @@ -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: @@ -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.""" @@ -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 "Restart of Home Assistant required" + 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 += ( + "You need to restart" + " Home Assistant manually after updating.\n\n" + ) + if self.repository.data.category == HacsCategory.PLUGIN: + release_notes += ( + "You need to manually" + " clear the frontend cache after updating.\n\n" + ) + + return release_notes