diff --git a/custom_components/hacs/repositories/base.py b/custom_components/hacs/repositories/base.py index b52536e29ff..e1041d89600 100644 --- a/custom_components/hacs/repositories/base.py +++ b/custom_components/hacs/repositories/base.py @@ -657,8 +657,9 @@ def cleanup_temp_dir(): except BaseException: # lgtm [py/catch-base-exception] pylint: disable=broad-except validate.errors.append("Download was not completed") - async def download_content(self) -> None: + async def download_content(self, version: string | None = None) -> None: """Download the content of a directory.""" + contents: list[FileInformation] | None = None if self.hacs.configuration.experimental: if ( not self.repository_manifest.zip_release @@ -672,9 +673,15 @@ async def download_content(self) -> None: except HacsException as exception: self.logger.exception(exception) - contents = self.gather_files_to_download() if self.repository_manifest.filename: self.logger.debug("%s %s", self.string, self.repository_manifest.filename) + + if self.content.path.remote == "release" and version is not None: + contents = await self.release_contents(version) + + if not contents: + contents = self.gather_files_to_download() + if not contents: raise HacsException("No content to download") @@ -1036,6 +1043,7 @@ async def async_install_repository(self, *, version: str | None = None, **_) -> self.hacs.log.debug("%s Local path is set to %s", self.string, self.content.path.local) self.hacs.log.debug("%s Remote path is set to %s", self.string, self.content.path.remote) + self.hacs.log.debug("%s Version to install: %s", self.string, version_to_install) self.hacs.async_dispatch( HacsDispatchEvent.REPOSITORY_DOWNLOAD_PROGRESS, @@ -1045,7 +1053,7 @@ async def async_install_repository(self, *, version: str | None = None, **_) -> if self.repository_manifest.zip_release and version_to_install != self.data.default_branch: await self.download_zip_files(self.validate) else: - await self.download_content() + await self.download_content(version_to_install) self.hacs.async_dispatch( HacsDispatchEvent.REPOSITORY_DOWNLOAD_PROGRESS, @@ -1294,6 +1302,25 @@ def gather_files_to_download(self) -> list[FileInformation]: files.append(FileInformation(path.download_url, path.full_path, path.filename)) return files + async def release_contents(self, version: str | None = None) -> list[FileInformation] | None: + """Gather the contents of a release.""" + release = await self.hacs.async_github_api_method( + method=self.hacs.githubapi.generic, + endpoint=f"/repos/{self.data.full_name}/releases/tags/{version}", + raise_exception=False, + ) + if release is None: + return None + + return [ + FileInformation( + url=asset.get("browser_download_url"), + path=asset.get("name"), + name=asset.get("name"), + ) + for asset in release.data.get("assets", []) + ] + @concurrent(concurrenttasks=10) async def dowload_repository_content(self, content: FileInformation) -> None: """Download content.""" diff --git a/custom_components/hacs/update.py b/custom_components/hacs/update.py index f7531aeaa89..85d5e144ea5 100644 --- a/custom_components/hacs/update.py +++ b/custom_components/hacs/update.py @@ -11,6 +11,7 @@ from .const import DOMAIN from .entity import HacsRepositoryEntity from .enums import HacsCategory, HacsDispatchEvent +from .exceptions import HacsException async def async_setup_entry(hass, _config_entry, async_add_devices): @@ -99,8 +100,14 @@ async def async_install(self, version: str | None, backup: bool, **kwargs: Any) self.repository.force_branch = version is not None self._update_in_progress(progress=20) - await self.repository.async_install(version=version) - self._update_in_progress(progress=False) + try: + await self.repository.async_install(version=version) + except HacsException as exception: + raise HomeAssistantError( + f"{exception} for {version}" if version else exception + ) from exception + finally: + self._update_in_progress(progress=False) async def async_release_notes(self) -> str | None: """Return the release notes."""