mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-08-20 12:10:28 +00:00
#743 - Trying to fix this.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""Class for appdaemon apps in HACS."""
|
||||
from aiogithubapi import AIOGitHubException
|
||||
from aiogithubapi import AIOGitHubAPIException
|
||||
from integrationhelper import Logger
|
||||
|
||||
from .repository import HacsRepository
|
||||
@@ -30,7 +30,7 @@ class HacsAppdaemon(HacsRepository):
|
||||
# Custom step 1: Validate content.
|
||||
try:
|
||||
addir = await self.repository_object.get_contents("apps", self.ref)
|
||||
except AIOGitHubException:
|
||||
except AIOGitHubAPIException:
|
||||
raise HacsException(
|
||||
f"Repostitory structure for {self.ref.replace('tags/','')} is not compliant"
|
||||
)
|
||||
@@ -64,11 +64,9 @@ class HacsAppdaemon(HacsRepository):
|
||||
# Set local path
|
||||
self.content.path.local = self.localpath
|
||||
|
||||
async def update_repository(self):
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
# Get appdaemon objects.
|
||||
if self.repository_manifest:
|
||||
|
@@ -74,11 +74,9 @@ class HacsIntegration(HacsRepository):
|
||||
# Set local path
|
||||
self.content.path.local = self.localpath
|
||||
|
||||
async def update_repository(self):
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
if self.data.content_in_root:
|
||||
self.content.path.remote = ""
|
||||
|
@@ -72,11 +72,9 @@ class HacsNetdaemon(HacsRepository):
|
||||
# Set local path
|
||||
self.content.path.local = self.localpath
|
||||
|
||||
async def update_repository(self):
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
# Get appdaemon objects.
|
||||
if self.repository_manifest:
|
||||
|
@@ -57,19 +57,13 @@ class HacsPlugin(HacsRepository):
|
||||
# Run common registration steps.
|
||||
await self.common_registration()
|
||||
|
||||
async def update_repository(self):
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
# Run common update steps.
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
# Get plugin objects.
|
||||
find_file_name(self)
|
||||
|
||||
# Get JS type
|
||||
await self.parse_readme_for_jstype()
|
||||
|
||||
if self.content.path.remote is None:
|
||||
self.validate.errors.append("Repostitory structure not compliant")
|
||||
|
||||
@@ -86,25 +80,3 @@ class HacsPlugin(HacsRepository):
|
||||
self.data.authors = package["author"]
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
|
||||
async def parse_readme_for_jstype(self):
|
||||
"""Parse the readme looking for js type."""
|
||||
readme = None
|
||||
readme_files = ["readme", "readme.md"]
|
||||
root = await self.repository_object.get_contents("")
|
||||
for file in root:
|
||||
if file.name.lower() in readme_files:
|
||||
readme = await self.repository_object.get_contents(file.name)
|
||||
break
|
||||
|
||||
if readme is None:
|
||||
return
|
||||
|
||||
readme = readme.content
|
||||
for line in readme.splitlines():
|
||||
if "type: module" in line:
|
||||
self.information.javascript_type = "module"
|
||||
break
|
||||
elif "type: js" in line:
|
||||
self.information.javascript_type = "js"
|
||||
break
|
||||
|
@@ -63,12 +63,9 @@ class HacsPythonScript(HacsRepository):
|
||||
# Set name
|
||||
find_file_name(self)
|
||||
|
||||
async def update_repository(self): # lgtm[py/similar-function]
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
# Run common update steps.
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
# Get python_script objects.
|
||||
if self.data.content_in_root:
|
||||
|
@@ -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},
|
||||
|
@@ -8,32 +8,52 @@ import attr
|
||||
class RepositoryData:
|
||||
"""RepositoryData class."""
|
||||
|
||||
id: int = 0
|
||||
full_name: str = ""
|
||||
pushed_at: str = ""
|
||||
category: str = ""
|
||||
archived: bool = False
|
||||
description: str = ""
|
||||
manifest_name: str = None
|
||||
topics: List[str] = []
|
||||
fork: bool = False
|
||||
domain: str = ""
|
||||
default_branch: str = None
|
||||
stargazers_count: int = 0
|
||||
last_commit: str = ""
|
||||
file_name: str = ""
|
||||
content_in_root: bool = False
|
||||
zip_release: bool = False
|
||||
filename: str = ""
|
||||
render_readme: bool = False
|
||||
hide_default_branch: bool = False
|
||||
domains: List[str] = []
|
||||
country: List[str] = []
|
||||
authors: List[str] = []
|
||||
homeassistant: str = None # Minimum Home Assistant version
|
||||
category: str = ""
|
||||
content_in_root: bool = False
|
||||
country: List[str] = []
|
||||
config_flow: bool = False
|
||||
default_branch: str = None
|
||||
description: str = ""
|
||||
domain: str = ""
|
||||
domains: List[str] = []
|
||||
downloads: int = 0
|
||||
file_name: str = ""
|
||||
filename: str = ""
|
||||
first_install: bool = False
|
||||
fork: bool = False
|
||||
full_name: str = ""
|
||||
hacs: str = None # Minimum HACS version
|
||||
persistent_directory: str = None
|
||||
hide: bool = False
|
||||
hide_default_branch: bool = False
|
||||
homeassistant: str = None # Minimum Home Assistant version
|
||||
id: int = 0
|
||||
iot_class: str = None
|
||||
installed: bool = False
|
||||
installed_commit: str = None
|
||||
installed_version: str = None
|
||||
open_issues: int = 0
|
||||
last_commit: str = None
|
||||
last_version: str = None
|
||||
last_updated: str = 0
|
||||
manifest_name: str = None
|
||||
new: bool = True
|
||||
persistent_directory: str = None
|
||||
pushed_at: str = ""
|
||||
releases: bool = False
|
||||
render_readme: bool = False
|
||||
published_tags: List[str] = []
|
||||
selected_tag: str = None
|
||||
show_beta: bool = False
|
||||
stargazers_count: int = 0
|
||||
topics: List[str] = []
|
||||
zip_release: bool = False
|
||||
|
||||
@property
|
||||
def stars(self):
|
||||
"""Return the stargazers count."""
|
||||
return self.stargazers_count or 0
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -53,9 +73,20 @@ class RepositoryData:
|
||||
for key in source:
|
||||
if key in data.__dict__:
|
||||
if key == "pushed_at":
|
||||
setattr(
|
||||
data, key, datetime.strptime(source[key], "%Y-%m-%dT%H:%M:%SZ")
|
||||
)
|
||||
if "Z" in source[key]:
|
||||
setattr(
|
||||
data,
|
||||
key,
|
||||
datetime.strptime(source[key], "%Y-%m-%dT%H:%M:%SZ"),
|
||||
)
|
||||
else:
|
||||
setattr(
|
||||
data,
|
||||
key,
|
||||
datetime.strptime(source[key], "%Y-%m-%dT%H:%M:%S"),
|
||||
)
|
||||
elif key == "id":
|
||||
setattr(data, key, str(source[key]))
|
||||
elif key == "county":
|
||||
if isinstance(source[key], str):
|
||||
setattr(data, key, [source[key]])
|
||||
@@ -70,9 +101,18 @@ class RepositoryData:
|
||||
for key in data:
|
||||
if key in self.__dict__:
|
||||
if key == "pushed_at":
|
||||
setattr(
|
||||
self, key, datetime.strptime(data[key], "%Y-%m-%dT%H:%M:%SZ")
|
||||
)
|
||||
if "Z" in data[key]:
|
||||
setattr(
|
||||
self,
|
||||
key,
|
||||
datetime.strptime(data[key], "%Y-%m-%dT%H:%M:%SZ"),
|
||||
)
|
||||
else:
|
||||
setattr(
|
||||
self, key, datetime.strptime(data[key], "%Y-%m-%dT%H:%M:%S")
|
||||
)
|
||||
elif key == "id":
|
||||
setattr(self, key, str(data[key]))
|
||||
elif key == "county":
|
||||
if isinstance(data[key], str):
|
||||
setattr(self, key, [data[key]])
|
||||
|
@@ -59,12 +59,9 @@ class HacsTheme(HacsRepository):
|
||||
find_file_name(self)
|
||||
self.content.path.local = f"{self.hacs.system.config_path}/themes/{self.data.file_name.replace('.yaml', '')}"
|
||||
|
||||
async def update_repository(self): # lgtm[py/similar-function]
|
||||
async def update_repository(self, ignore_issues=False):
|
||||
"""Update."""
|
||||
if self.hacs.github.ratelimits.remaining == 0:
|
||||
return
|
||||
# Run common update steps.
|
||||
await self.common_update()
|
||||
await self.common_update(ignore_issues)
|
||||
|
||||
# Get theme objects.
|
||||
if self.data.content_in_root:
|
||||
|
Reference in New Issue
Block a user