mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-08-20 20:16:52 +00:00
#743 - Trying to fix this.
This commit is contained in:
@@ -5,7 +5,7 @@ import os
|
||||
import tempfile
|
||||
import zipfile
|
||||
from integrationhelper import Validate
|
||||
from aiogithubapi import AIOGitHubException
|
||||
from aiogithubapi import AIOGitHubAPIException
|
||||
from .manifest import HacsManifest
|
||||
from ..helpers.misc import get_repository_name
|
||||
from ..handler.download import async_download_file, async_save_file
|
||||
@@ -13,6 +13,7 @@ from ..helpers.misc import version_left_higher_then_right
|
||||
from ..helpers.install import install_repository, version_to_install
|
||||
|
||||
from custom_components.hacs.hacsbase.exceptions import HacsException
|
||||
from custom_components.hacs.store import async_remove_store
|
||||
from custom_components.hacs.globals import get_hacs
|
||||
from custom_components.hacs.helpers.information import (
|
||||
get_info_md_content,
|
||||
@@ -126,31 +127,22 @@ class HacsRepository:
|
||||
"""Return pending upgrade."""
|
||||
if not self.can_install:
|
||||
return False
|
||||
if self.status.installed:
|
||||
if self.status.selected_tag is not None:
|
||||
if self.status.selected_tag == self.data.default_branch:
|
||||
if self.versions.installed_commit != self.versions.available_commit:
|
||||
if self.data.installed:
|
||||
if self.data.selected_tag is not None:
|
||||
if self.data.selected_tag == self.data.default_branch:
|
||||
if self.data.installed_commit != self.data.last_commit:
|
||||
return True
|
||||
return False
|
||||
if self.display_installed_version != self.display_available_version:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def config_flow(self):
|
||||
"""Return bool if integration has config_flow."""
|
||||
if self.integration_manifest:
|
||||
if self.data.full_name == "hacs/integration":
|
||||
return False
|
||||
return self.integration_manifest.get("config_flow", False)
|
||||
return False
|
||||
|
||||
@property
|
||||
def custom(self):
|
||||
"""Return flag if the repository is custom."""
|
||||
if self.data.full_name.split("/")[0] in ["custom-components", "custom-cards"]:
|
||||
return False
|
||||
if self.data.full_name.lower() in [x.lower() for x in self.hacs.common.default]:
|
||||
if str(self.data.id) in [str(x) for x in self.hacs.common.default]:
|
||||
return False
|
||||
if self.data.full_name == "hacs/integration":
|
||||
return False
|
||||
@@ -160,14 +152,13 @@ class HacsRepository:
|
||||
def can_install(self):
|
||||
"""Return bool if repository can be installed."""
|
||||
target = None
|
||||
if self.information.homeassistant_version is not None:
|
||||
target = self.information.homeassistant_version
|
||||
if self.repository_manifest is not None:
|
||||
if self.data.homeassistant is not None:
|
||||
target = self.data.homeassistant
|
||||
if self.data.homeassistant is not None:
|
||||
target = self.data.homeassistant
|
||||
if self.data.homeassistant is not None:
|
||||
target = self.data.homeassistant
|
||||
|
||||
if target is not None:
|
||||
if self.releases.releases:
|
||||
if self.data.releases:
|
||||
if not version_left_higher_then_right(
|
||||
self.hacs.system.ha_version, target
|
||||
):
|
||||
@@ -182,13 +173,13 @@ class HacsRepository:
|
||||
@property
|
||||
def display_status(self):
|
||||
"""Return display_status."""
|
||||
if self.status.new:
|
||||
if self.data.new:
|
||||
status = "new"
|
||||
elif self.pending_restart:
|
||||
status = "pending-restart"
|
||||
elif self.pending_upgrade:
|
||||
status = "pending-upgrade"
|
||||
elif self.status.installed:
|
||||
elif self.data.installed:
|
||||
status = "installed"
|
||||
else:
|
||||
status = "default"
|
||||
@@ -209,11 +200,11 @@ class HacsRepository:
|
||||
@property
|
||||
def display_installed_version(self):
|
||||
"""Return display_authors"""
|
||||
if self.versions.installed is not None:
|
||||
installed = self.versions.installed
|
||||
if self.data.installed_version is not None:
|
||||
installed = self.data.installed_version
|
||||
else:
|
||||
if self.versions.installed_commit is not None:
|
||||
installed = self.versions.installed_commit
|
||||
if self.data.installed_commit is not None:
|
||||
installed = self.data.installed_commit
|
||||
else:
|
||||
installed = ""
|
||||
return installed
|
||||
@@ -221,11 +212,11 @@ class HacsRepository:
|
||||
@property
|
||||
def display_available_version(self):
|
||||
"""Return display_authors"""
|
||||
if self.versions.available is not None:
|
||||
available = self.versions.available
|
||||
if self.data.last_version is not None:
|
||||
available = self.data.last_version
|
||||
else:
|
||||
if self.versions.available_commit is not None:
|
||||
available = self.versions.available_commit
|
||||
if self.data.last_commit is not None:
|
||||
available = self.data.last_commit
|
||||
else:
|
||||
available = ""
|
||||
return available
|
||||
@@ -233,7 +224,7 @@ class HacsRepository:
|
||||
@property
|
||||
def display_version_or_commit(self):
|
||||
"""Does the repositoriy use releases or commits?"""
|
||||
if self.releases.releases:
|
||||
if self.data.releases:
|
||||
version_or_commit = "version"
|
||||
else:
|
||||
version_or_commit = "commit"
|
||||
@@ -251,9 +242,9 @@ class HacsRepository:
|
||||
}
|
||||
return actions[self.display_status]
|
||||
|
||||
async def common_validate(self):
|
||||
async def common_validate(self, ignore_issues=False):
|
||||
"""Common validation steps of the repository."""
|
||||
await common_validate(self)
|
||||
await common_validate(self, ignore_issues)
|
||||
|
||||
async def common_registration(self):
|
||||
"""Common registration steps of the repository."""
|
||||
@@ -264,9 +255,6 @@ class HacsRepository:
|
||||
)
|
||||
self.data.update_data(self.repository_object.attributes)
|
||||
|
||||
# Set id
|
||||
self.information.uid = str(self.data.id)
|
||||
|
||||
# Set topics
|
||||
self.data.topics = self.data.topics
|
||||
|
||||
@@ -280,21 +268,19 @@ class HacsRepository:
|
||||
if self.data.description is None or len(self.data.description) == 0:
|
||||
raise HacsException("Missing repository description")
|
||||
|
||||
async def common_update(self):
|
||||
async def common_update(self, ignore_issues=False):
|
||||
"""Common information update steps of the repository."""
|
||||
self.logger.debug("Getting repository information")
|
||||
|
||||
# Attach repository
|
||||
await common_update_data(self)
|
||||
await common_update_data(self, ignore_issues)
|
||||
|
||||
# Update last updaeted
|
||||
self.information.last_updated = self.repository_object.attributes.get(
|
||||
"pushed_at", 0
|
||||
)
|
||||
self.data.last_updated = self.repository_object.attributes.get("pushed_at", 0)
|
||||
|
||||
# Update last available commit
|
||||
await self.repository_object.set_last_commit()
|
||||
self.versions.available_commit = self.repository_object.last_commit
|
||||
self.data.last_commit = self.repository_object.last_commit
|
||||
|
||||
# Get the content of hacs.json
|
||||
await self.get_repository_manifest_content()
|
||||
@@ -357,30 +343,30 @@ class HacsRepository:
|
||||
raise HacsException("No hacs.json file in the root of the repository.")
|
||||
return
|
||||
if self.hacs.action:
|
||||
self.logger.debug("Found hacs.json")
|
||||
self.logger.info("Found hacs.json")
|
||||
|
||||
self.ref = version_to_install(self)
|
||||
|
||||
if self.ref is None:
|
||||
self.ref = version_to_install(self)
|
||||
try:
|
||||
manifest = await self.repository_object.get_contents("hacs.json", self.ref)
|
||||
self.repository_manifest = HacsManifest.from_dict(
|
||||
json.loads(manifest.content)
|
||||
)
|
||||
self.data.update_data(json.loads(manifest.content))
|
||||
except (AIOGitHubException, Exception) as exception: # Gotta Catch 'Em All
|
||||
except (AIOGitHubAPIException, Exception) as exception: # Gotta Catch 'Em All
|
||||
if self.hacs.action:
|
||||
raise HacsException(f"hacs.json file is not valid ({exception}).")
|
||||
if self.hacs.action:
|
||||
self.logger.debug("hacs.json is valid")
|
||||
self.logger.info("hacs.json is valid")
|
||||
|
||||
def remove(self):
|
||||
"""Run remove tasks."""
|
||||
self.logger.info("Starting removal")
|
||||
|
||||
if self.information.uid in self.hacs.common.installed:
|
||||
self.hacs.common.installed.remove(self.information.uid)
|
||||
if self.data.id in self.hacs.common.installed:
|
||||
self.hacs.common.installed.remove(self.data.id)
|
||||
for repository in self.hacs.repositories:
|
||||
if repository.information.uid == self.information.uid:
|
||||
if repository.data.id == self.data.id:
|
||||
self.hacs.repositories.remove(repository)
|
||||
|
||||
async def uninstall(self):
|
||||
@@ -388,9 +374,9 @@ class HacsRepository:
|
||||
self.logger.info("Uninstalling")
|
||||
if not await self.remove_local_directory():
|
||||
raise HacsException("Could not uninstall")
|
||||
self.status.installed = False
|
||||
self.data.installed = False
|
||||
if self.data.category == "integration":
|
||||
if self.config_flow:
|
||||
if self.data.config_flow:
|
||||
await self.reload_custom_components()
|
||||
else:
|
||||
self.pending_restart = True
|
||||
@@ -403,8 +389,11 @@ class HacsRepository:
|
||||
pass
|
||||
if self.data.full_name in self.hacs.common.installed:
|
||||
self.hacs.common.installed.remove(self.data.full_name)
|
||||
self.versions.installed = None
|
||||
self.versions.installed_commit = None
|
||||
|
||||
await async_remove_store(self.hacs.hass, f"hacs/{self.data.id}.hacs")
|
||||
|
||||
self.data.installed_version = None
|
||||
self.data.installed_commit = None
|
||||
self.hacs.hass.bus.async_fire(
|
||||
"hacs/repository",
|
||||
{"id": 1337, "action": "uninstall", "repository": self.data.full_name},
|
||||
|
Reference in New Issue
Block a user