From 8056390e49f1ae8672c761a2f4247cf37c9667e4 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 4 Mar 2023 12:15:50 -0800 Subject: [PATCH] Roll HACS to 1.31.0 --- custom_components/hacs/base.py | 42 ++++++++++++++--- custom_components/hacs/manifest.json | 6 +-- custom_components/hacs/repositories/base.py | 50 +++++++++++++-------- custom_components/hacs/translations/en.json | 2 +- custom_components/hacs/utils/backup.py | 4 +- custom_components/hacs/utils/data.py | 6 ++- custom_components/hacs/utils/store.py | 4 +- custom_components/hacs/utils/template.py | 4 +- 8 files changed, 86 insertions(+), 32 deletions(-) diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index 80def76..5a97c55 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -457,7 +457,9 @@ class HacsBase: try: await self.hass.async_add_executor_job(_write_file) - except BaseException as error: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as error: self.log.error("Could not write data to %s - %s", file_path, error) return False @@ -476,7 +478,9 @@ class HacsBase: f"{reset.hour}:{reset.minute}:{reset.second}", ) self.disable_hacs(HacsDisabledReason.RATE_LIMIT) - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.log.exception(exception) return 0 @@ -515,7 +519,9 @@ class HacsBase: raise exception except GitHubException as exception: _exception = exception - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.log.exception(exception) _exception = exception @@ -726,7 +732,9 @@ class HacsBase: await asyncio.sleep(1) continue - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.log.exception("Download failed - %s", exception) return None @@ -742,7 +750,9 @@ class HacsBase: entry=self.configuration.config_entry, platforms=platforms, ) - self.hass.config_entries.async_setup_platforms(self.configuration.config_entry, platforms) + await self.hass.config_entries.async_forward_entry_setups( + self.configuration.config_entry, platforms + ) @callback def async_dispatch(self, signal: HacsDispatchEvent, data: dict | None = None) -> None: @@ -764,7 +774,18 @@ class HacsBase: if self.configuration.appdaemon: self.enable_hacs_category(HacsCategory.APPDAEMON) if self.configuration.netdaemon: - self.enable_hacs_category(HacsCategory.NETDAEMON) + downloaded_netdaemon = [ + x + for x in self.repositories.list_downloaded + if x.data.category == HacsCategory.NETDAEMON + ] + if len(downloaded_netdaemon) != 0: + self.log.warning( + "NetDaemon in HACS is deprectaded. It will stop working in the future. " + "Please remove all your current NetDaemon repositories from HACS " + "and download them manually if you want to continue using them." + ) + self.enable_hacs_category(HacsCategory.NETDAEMON) async def async_load_hacs_from_github(self, _=None) -> None: """Load HACS from GitHub.""" @@ -849,6 +870,15 @@ class HacsBase: repository.repository_manifest.update_data( {**dict(HACS_MANIFEST_KEYS_TO_EXPORT), **manifest} ) + self.async_dispatch( + HacsDispatchEvent.REPOSITORY, + { + "id": 1337, + "action": "update", + "repository": repository.data.full_name, + "repository_id": repository.data.id, + }, + ) if category == "integration": self.status.inital_fetch_done = True diff --git a/custom_components/hacs/manifest.json b/custom_components/hacs/manifest.json index dea58ad..fb8a0af 100644 --- a/custom_components/hacs/manifest.json +++ b/custom_components/hacs/manifest.json @@ -1,4 +1,6 @@ { + "domain": "hacs", + "name": "HACS", "codeowners": [ "@ludeeus" ], @@ -12,12 +14,10 @@ "repairs" ], "documentation": "https://hacs.xyz/docs/configuration/start", - "domain": "hacs", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/hacs/integration/issues", - "name": "HACS", "requirements": [ "aiogithubapi>=22.10.1" ], - "version": "1.30.1" + "version": "1.31.0" } \ No newline at end of file diff --git a/custom_components/hacs/repositories/base.py b/custom_components/hacs/repositories/base.py index 6042236..c35ce69 100644 --- a/custom_components/hacs/repositories/base.py +++ b/custom_components/hacs/repositories/base.py @@ -102,6 +102,7 @@ REPOSITORY_KEYS_TO_EXPORT = ( ("description", ""), ("downloads", 0), ("domain", None), + ("etag_releases", None), ("etag_repository", None), ("full_name", ""), ("last_commit", None), @@ -143,6 +144,7 @@ class RepositoryData: domain: str = None downloads: int = 0 etag_repository: str = None + etag_releases: str = None file_name: str = "" first_install: bool = False full_name: str = "" @@ -505,14 +507,18 @@ class HacsRepository: self.data.description = self.data.description @concurrent(concurrenttasks=10, backoff_time=5) - async def common_update(self, ignore_issues=False, force=False) -> bool: + async def common_update(self, ignore_issues=False, force=False, skip_releases=False) -> bool: """Common information update steps of the repository.""" self.logger.debug("%s Getting repository information", self.string) # Attach repository current_etag = self.data.etag_repository try: - await self.common_update_data(ignore_issues=ignore_issues, force=force) + await self.common_update_data( + ignore_issues=ignore_issues, + force=force, + skip_releases=skip_releases, + ) except HacsRepositoryExistException: self.data.full_name = self.hacs.common.renamed_repositories[self.data.full_name] await self.common_update_data(ignore_issues=ignore_issues, force=force) @@ -746,9 +752,8 @@ class HacsRepository: def remove(self) -> None: """Run remove tasks.""" - self.logger.info("%s Starting removal", self.string) - if self.hacs.repositories.is_registered(repository_id=str(self.data.id)): + self.logger.info("%s Starting removal", self.string) self.hacs.repositories.unregister(self) async def uninstall(self) -> None: @@ -830,7 +835,9 @@ class HacsRepository: "%s Presumed local content path %s does not exist", self.string, local_path ) - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.logger.debug("%s Removing %s failed with %s", self.string, local_path, exception) return False return True @@ -1048,6 +1055,7 @@ class HacsRepository: ignore_issues: bool = False, force: bool = False, retry=False, + skip_releases=False, ) -> None: """Common update data.""" releases = [] @@ -1096,19 +1104,20 @@ class HacsRepository: raise HacsException(f"{self} Repository has been requested to be removed.") # Get releases. - try: - releases = await self.get_releases( - prerelease=self.data.show_beta, - returnlimit=self.hacs.configuration.release_limit, - ) - if releases: - self.data.releases = True - self.releases.objects = releases - self.data.published_tags = [x.tag_name for x in self.releases.objects] - self.data.last_version = next(iter(self.data.published_tags)) + if not skip_releases: + try: + releases = await self.get_releases( + prerelease=self.data.show_beta, + returnlimit=self.hacs.configuration.release_limit, + ) + if releases: + self.data.releases = True + self.releases.objects = releases + self.data.published_tags = [x.tag_name for x in self.releases.objects] + self.data.last_version = next(iter(self.data.published_tags)) - except HacsException: - self.data.releases = False + except HacsException: + self.data.releases = False if not self.force_branch: self.ref = self.version_to_download() @@ -1118,6 +1127,9 @@ class HacsRepository: if assets := release.assets: downloads = next(iter(assets)).download_count self.data.downloads = downloads + elif self.hacs.system.generator and self.repository_object: + await self.repository_object.set_last_commit() + self.data.last_commit = self.repository_object.last_commit self.hacs.log.debug( "%s Running checks against %s", self.string, self.ref.replace("tags/", "") @@ -1247,7 +1259,9 @@ class HacsRepository: return self.validate.errors.append(f"[{content.name}] was not downloaded.") - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.validate.errors.append(f"Download was not completed [{exception}]") async def async_remove_entity_device(self) -> None: diff --git a/custom_components/hacs/translations/en.json b/custom_components/hacs/translations/en.json index 88adb7e..e0451b2 100644 --- a/custom_components/hacs/translations/en.json +++ b/custom_components/hacs/translations/en.json @@ -47,7 +47,7 @@ "release_limit": "Number of releases to show.", "debug": "Enable debug.", "appdaemon": "Enable AppDaemon apps discovery & tracking", - "netdaemon": "Enable NetDaemon apps discovery & tracking", + "netdaemon": "[DEPRECATED] Enable NetDaemon apps discovery & tracking", "sidepanel_icon": "Side panel icon", "sidepanel_title": "Side panel title" } diff --git a/custom_components/hacs/utils/backup.py b/custom_components/hacs/utils/backup.py index df17cb6..3f78558 100644 --- a/custom_components/hacs/utils/backup.py +++ b/custom_components/hacs/utils/backup.py @@ -74,7 +74,9 @@ class Backup: self.local_path, self.backup_path_full, ) - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.hacs.log.warning("Could not create backup: %s", exception) def restore(self) -> None: diff --git a/custom_components/hacs/utils/data.py b/custom_components/hacs/utils/data.py index 067b71d..76616dc 100644 --- a/custom_components/hacs/utils/data.py +++ b/custom_components/hacs/utils/data.py @@ -241,7 +241,9 @@ class HacsData: self.async_restore_repository(entry, repo_data) self.logger.info(" Restore done") - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: self.logger.critical( " [%s] Restore Failed!", exception, exc_info=exception ) @@ -282,6 +284,8 @@ class HacsData: repository.data.description = repository_data.get("description", "") repository.data.downloads = repository_data.get("downloads", 0) repository.data.last_updated = repository_data.get("last_updated", 0) + if self.hacs.system.generator: + repository.data.etag_releases = repository_data.get("etag_releases") repository.data.etag_repository = repository_data.get("etag_repository") repository.data.topics = [ topic for topic in repository_data.get("topics", []) if topic not in TOPIC_FILTER diff --git a/custom_components/hacs/utils/store.py b/custom_components/hacs/utils/store.py index 54eace0..d3a0fc5 100644 --- a/custom_components/hacs/utils/store.py +++ b/custom_components/hacs/utils/store.py @@ -17,7 +17,9 @@ class HACSStore(Store): """Load the data from disk if version matches.""" try: data = json_util.load_json(self.path) - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: _LOGGER.critical( "Could not load '%s', restore it from a backup or delete the file: %s", self.path, diff --git a/custom_components/hacs/utils/template.py b/custom_components/hacs/utils/template.py index 53e3f33..425e2da 100644 --- a/custom_components/hacs/utils/template.py +++ b/custom_components/hacs/utils/template.py @@ -31,6 +31,8 @@ def render_template(hacs: HacsBase, content: str, context: HacsRepository) -> st version_available=context.releases.last_release, version_installed=context.display_installed_version, ) - except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except + except ( + BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except + ) as exception: context.logger.debug(exception) return content