mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-08-19 03:29:34 +00:00
Updated HACS and also fixed Garadget #727
This commit is contained in:
92
config/custom_components/hacs/helpers/install.py
Executable file → Normal file
92
config/custom_components/hacs/helpers/install.py
Executable file → Normal file
@@ -1,14 +1,17 @@
|
||||
"""Install helper for repositories."""
|
||||
import os
|
||||
import tempfile
|
||||
from custom_components.hacs.globals import get_hacs
|
||||
from custom_components.hacs.hacsbase.exceptions import HacsException
|
||||
from custom_components.hacs.hacsbase.backup import Backup
|
||||
from custom_components.hacs.hacsbase.backup import Backup, BackupNetDaemon
|
||||
from custom_components.hacs.helpers.download import download_content
|
||||
|
||||
|
||||
async def install_repository(repository):
|
||||
"""Common installation steps of the repository."""
|
||||
persistent_directory = None
|
||||
await repository.update_repository()
|
||||
repository.validate.errors = []
|
||||
|
||||
if not repository.can_install:
|
||||
raise HacsException(
|
||||
@@ -16,41 +19,36 @@ async def install_repository(repository):
|
||||
)
|
||||
|
||||
version = version_to_install(repository)
|
||||
if version == repository.information.default_branch:
|
||||
if version == repository.data.default_branch:
|
||||
repository.ref = version
|
||||
else:
|
||||
repository.ref = f"tags/{version}"
|
||||
|
||||
if repository.repository_manifest:
|
||||
if repository.repository_manifest.persistent_directory:
|
||||
if os.path.exists(
|
||||
f"{repository.content.path.local}/{repository.repository_manifest.persistent_directory}"
|
||||
):
|
||||
persistent_directory = Backup(
|
||||
f"{repository.content.path.local}/{repository.repository_manifest.persistent_directory}",
|
||||
tempfile.gettempdir() + "/hacs_persistent_directory/",
|
||||
)
|
||||
persistent_directory.create()
|
||||
if repository.status.installed and repository.data.category == "netdaemon":
|
||||
persistent_directory = BackupNetDaemon(repository)
|
||||
persistent_directory.create()
|
||||
|
||||
elif repository.data.persistent_directory:
|
||||
if os.path.exists(
|
||||
f"{repository.content.path.local}/{repository.data.persistent_directory}"
|
||||
):
|
||||
persistent_directory = Backup(
|
||||
f"{repository.content.path.local}/{repository.data.persistent_directory}",
|
||||
tempfile.gettempdir() + "/hacs_persistent_directory/",
|
||||
)
|
||||
persistent_directory.create()
|
||||
|
||||
if repository.status.installed and not repository.content.single:
|
||||
backup = Backup(repository.content.path.local)
|
||||
backup.create()
|
||||
|
||||
if (
|
||||
repository.repository_manifest.zip_release
|
||||
and version != repository.information.default_branch
|
||||
):
|
||||
validate = await repository.download_zip(repository.validate)
|
||||
if repository.data.zip_release and version != repository.data.default_branch:
|
||||
await repository.download_zip(repository)
|
||||
else:
|
||||
validate = await repository.download_content(
|
||||
repository.validate,
|
||||
repository.content.path.remote,
|
||||
repository.content.path.local,
|
||||
repository.ref,
|
||||
)
|
||||
await download_content(repository)
|
||||
|
||||
if validate.errors:
|
||||
for error in validate.errors:
|
||||
if repository.validate.errors:
|
||||
for error in repository.validate.errors:
|
||||
repository.logger.error(error)
|
||||
if repository.status.installed and not repository.content.single:
|
||||
backup.restore()
|
||||
@@ -62,14 +60,14 @@ async def install_repository(repository):
|
||||
persistent_directory.restore()
|
||||
persistent_directory.cleanup()
|
||||
|
||||
if validate.success:
|
||||
if repository.information.full_name not in repository.common.installed:
|
||||
if repository.information.full_name == "hacs/integration":
|
||||
repository.common.installed.append(repository.information.full_name)
|
||||
if repository.validate.success:
|
||||
if repository.data.full_name not in repository.hacs.common.installed:
|
||||
if repository.data.full_name == "hacs/integration":
|
||||
repository.hacs.common.installed.append(repository.data.full_name)
|
||||
repository.status.installed = True
|
||||
repository.versions.installed_commit = repository.versions.available_commit
|
||||
|
||||
if version == repository.information.default_branch:
|
||||
if version == repository.data.default_branch:
|
||||
repository.versions.installed = None
|
||||
else:
|
||||
repository.versions.installed = version
|
||||
@@ -80,28 +78,34 @@ async def install_repository(repository):
|
||||
|
||||
async def reload_after_install(repository):
|
||||
"""Reload action after installation success."""
|
||||
if repository.information.category == "integration":
|
||||
if repository.data.category == "integration":
|
||||
if repository.config_flow:
|
||||
if repository.information.full_name != "hacs/integration":
|
||||
if repository.data.full_name != "hacs/integration":
|
||||
await repository.reload_custom_components()
|
||||
repository.pending_restart = True
|
||||
|
||||
elif repository.information.category == "theme":
|
||||
elif repository.data.category == "theme":
|
||||
try:
|
||||
await repository.hass.services.async_call("frontend", "reload_themes", {})
|
||||
await repository.hacs.hass.services.async_call(
|
||||
"frontend", "reload_themes", {}
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
elif repository.data.category == "netdaemon":
|
||||
try:
|
||||
await repository.hacs.hass.services.async_call(
|
||||
"hassio", "addon_restart", {"addon": "e466aeb3_netdaemon"}
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
|
||||
|
||||
def installation_complete(repository):
|
||||
"""Action to run when the installation is complete."""
|
||||
repository.hass.bus.async_fire(
|
||||
hacs = get_hacs()
|
||||
hacs.hass.bus.async_fire(
|
||||
"hacs/repository",
|
||||
{
|
||||
"id": 1337,
|
||||
"action": "install",
|
||||
"repository": repository.information.full_name,
|
||||
},
|
||||
{"id": 1337, "action": "install", "repository": repository.data.full_name},
|
||||
)
|
||||
|
||||
|
||||
@@ -115,10 +119,10 @@ def version_to_install(repository):
|
||||
return repository.status.selected_tag
|
||||
return repository.versions.available
|
||||
if repository.status.selected_tag is not None:
|
||||
if repository.status.selected_tag == repository.information.default_branch:
|
||||
return repository.information.default_branch
|
||||
if repository.status.selected_tag == repository.data.default_branch:
|
||||
return repository.data.default_branch
|
||||
if repository.status.selected_tag in repository.releases.published_tags:
|
||||
return repository.status.selected_tag
|
||||
if repository.information.default_branch is None:
|
||||
if repository.data.default_branch is None:
|
||||
return "master"
|
||||
return repository.information.default_branch
|
||||
return repository.data.default_branch
|
||||
|
Reference in New Issue
Block a user