Updated HACS and also fixed Garadget #727

This commit is contained in:
ccostan
2020-04-09 21:29:27 -04:00
parent 51aab60dea
commit e6e0d442e9
65 changed files with 1510 additions and 1047 deletions

126
config/custom_components/hacs/ws_api_handlers.py Executable file → Normal file
View File

@@ -6,10 +6,12 @@ import voluptuous as vol
from aiogithubapi import AIOGitHubException
from homeassistant.components import websocket_api
import homeassistant.helpers.config_validation as cv
from .hacsbase import Hacs
from .hacsbase.exceptions import HacsException
from .store import async_load_from_store, async_save_to_store
from custom_components.hacs.globals import get_hacs
from custom_components.hacs.helpers.register_repository import register_repository
async def setup_ws_api(hass):
"""Set up WS API handlers."""
@@ -34,74 +36,76 @@ async def setup_ws_api(hass):
)
async def hacs_settings(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
action = msg["action"]
Hacs().logger.debug(f"WS action '{action}'")
hacs.logger.debug(f"WS action '{action}'")
if action == "set_fe_grid":
Hacs().configuration.frontend_mode = "Grid"
hacs.configuration.frontend_mode = "Grid"
elif action == "onboarding_done":
Hacs().configuration.onboarding_done = True
hacs.configuration.onboarding_done = True
elif action == "set_fe_table":
Hacs().configuration.frontend_mode = "Table"
hacs.configuration.frontend_mode = "Table"
elif action == "set_fe_compact_true":
Hacs().configuration.frontend_compact = False
hacs.configuration.frontend_compact = False
elif action == "set_fe_compact_false":
Hacs().configuration.frontend_compact = True
hacs.configuration.frontend_compact = True
elif action == "reload_data":
Hacs().system.status.reloading_data = True
hacs.system.status.reloading_data = True
hass.bus.async_fire("hacs/status", {})
await Hacs().recuring_tasks_all()
Hacs().system.status.reloading_data = False
await hacs.recuring_tasks_all()
hacs.system.status.reloading_data = False
hass.bus.async_fire("hacs/status", {})
elif action == "upgrade_all":
Hacs().system.status.upgrading_all = True
Hacs().system.status.background_task = True
hacs.system.status.upgrading_all = True
hacs.system.status.background_task = True
hass.bus.async_fire("hacs/status", {})
for repository in Hacs().repositories:
for repository in hacs.repositories:
if repository.pending_upgrade:
repository.status.selected_tag = None
await repository.install()
Hacs().system.status.upgrading_all = False
Hacs().system.status.background_task = False
hacs.system.status.upgrading_all = False
hacs.system.status.background_task = False
hass.bus.async_fire("hacs/status", {})
hass.bus.async_fire("hacs/repository", {})
elif action == "clear_new":
for repo in Hacs().repositories:
if msg.get("category") == repo.information.category:
for repo in hacs.repositories:
if msg.get("category") == repo.data.category:
if repo.status.new:
Hacs().logger.debug(
f"Clearing new flag from '{repo.information.full_name}'"
hacs.logger.debug(
f"Clearing new flag from '{repo.data.full_name}'"
)
repo.status.new = False
else:
Hacs().logger.error(f"WS action '{action}' is not valid")
hacs.logger.error(f"WS action '{action}' is not valid")
hass.bus.async_fire("hacs/config", {})
await Hacs().data.async_write()
await hacs.data.async_write()
@websocket_api.async_response
@websocket_api.websocket_command({vol.Required("type"): "hacs/config"})
async def hacs_config(hass, connection, msg):
"""Handle get media player cover command."""
config = Hacs().configuration
hacs = get_hacs()
config = hacs.configuration
content = {}
content["frontend_mode"] = config.frontend_mode
content["frontend_compact"] = config.frontend_compact
content["onboarding_done"] = config.onboarding_done
content["version"] = Hacs().version
content["version"] = hacs.version
content["dev"] = config.dev
content["debug"] = config.debug
content["country"] = config.country
content["experimental"] = config.experimental
content["categories"] = Hacs().common.categories
content["categories"] = hacs.common.categories
connection.send_message(websocket_api.result_message(msg["id"], content))
@@ -110,13 +114,14 @@ async def hacs_config(hass, connection, msg):
@websocket_api.websocket_command({vol.Required("type"): "hacs/status"})
async def hacs_status(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
content = {
"startup": Hacs().system.status.startup,
"background_task": Hacs().system.status.background_task,
"lovelace_mode": Hacs().system.lovelace_mode,
"reloading_data": Hacs().system.status.reloading_data,
"upgrading_all": Hacs().system.status.upgrading_all,
"disabled": Hacs().system.disabled,
"startup": hacs.system.status.startup,
"background_task": hacs.system.status.background_task,
"lovelace_mode": hacs.system.lovelace_mode,
"reloading_data": hacs.system.status.reloading_data,
"upgrading_all": hacs.system.status.upgrading_all,
"disabled": hacs.system.disabled,
}
connection.send_message(websocket_api.result_message(msg["id"], content))
@@ -125,30 +130,31 @@ async def hacs_status(hass, connection, msg):
@websocket_api.websocket_command({vol.Required("type"): "hacs/repositories"})
async def hacs_repositories(hass, connection, msg):
"""Handle get media player cover command."""
repositories = Hacs().repositories
hacs = get_hacs()
repositories = hacs.repositories
content = []
for repo in repositories:
if repo.information.category in Hacs().common.categories:
if repo.data.category in hacs.common.categories:
data = {
"additional_info": repo.information.additional_info,
"authors": repo.information.authors,
"authors": repo.data.authors,
"available_version": repo.display_available_version,
"beta": repo.status.show_beta,
"can_install": repo.can_install,
"category": repo.information.category,
"country": repo.repository_manifest.country,
"category": repo.data.category,
"country": repo.data.country,
"config_flow": repo.config_flow,
"custom": repo.custom,
"default_branch": repo.information.default_branch,
"description": repo.information.description,
"domain": repo.manifest.get("domain"),
"downloads": repo.releases.last_release_object_downloads,
"file_name": repo.information.file_name,
"default_branch": repo.data.default_branch,
"description": repo.data.description,
"domain": repo.integration_manifest.get("domain"),
"downloads": repo.releases.downloads,
"file_name": repo.data.file_name,
"first_install": repo.status.first_install,
"full_name": repo.information.full_name,
"full_name": repo.data.full_name,
"hide": repo.status.hide,
"hide_default_branch": repo.repository_manifest.hide_default_branch,
"homeassistant": repo.repository_manifest.homeassistant,
"hide_default_branch": repo.data.hide_default_branch,
"homeassistant": repo.data.homeassistant,
"id": repo.information.uid,
"info": repo.information.info,
"installed_version": repo.display_installed_version,
@@ -162,11 +168,11 @@ async def hacs_repositories(hass, connection, msg):
"pending_upgrade": repo.pending_upgrade,
"releases": repo.releases.published_tags,
"selected_tag": repo.status.selected_tag,
"stars": repo.information.stars,
"stars": repo.data.stargazers_count,
"state": repo.state,
"status_description": repo.display_status_description,
"status": repo.display_status,
"topics": repo.information.topics,
"topics": repo.data.topics,
"updated_info": repo.status.updated_info,
"version_or_commit": repo.display_version_or_commit,
}
@@ -186,6 +192,7 @@ async def hacs_repositories(hass, connection, msg):
)
async def hacs_repository(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
try:
repo_id = msg.get("repository")
action = msg.get("action")
@@ -193,8 +200,8 @@ async def hacs_repository(hass, connection, msg):
if repo_id is None or action is None:
return
repository = Hacs().get_by_id(repo_id)
Hacs().logger.debug(f"Running {action} for {repository.information.full_name}")
repository = hacs.get_by_id(repo_id)
hacs.logger.debug(f"Running {action} for {repository.data.full_name}")
if action == "update":
await repository.update_repository()
@@ -230,17 +237,17 @@ async def hacs_repository(hass, connection, msg):
repository.remove()
elif action == "set_version":
if msg["version"] == repository.information.default_branch:
if msg["version"] == repository.data.default_branch:
repository.status.selected_tag = None
else:
repository.status.selected_tag = msg["version"]
await repository.update_repository()
else:
Hacs().logger.error(f"WS action '{action}' is not valid")
hacs.logger.error(f"WS action '{action}' is not valid")
repository.state = None
await Hacs().data.async_write()
await hacs.data.async_write()
except AIOGitHubException as exception:
hass.bus.async_fire("hacs/error", {"message": str(exception)})
except AttributeError as exception:
@@ -262,6 +269,7 @@ async def hacs_repository(hass, connection, msg):
)
async def hacs_repository_data(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
repo_id = msg.get("repository")
action = msg.get("action")
data = msg.get("data")
@@ -273,12 +281,12 @@ async def hacs_repository_data(hass, connection, msg):
if "github." in repo_id:
repo_id = repo_id.split("github.com/")[1]
if repo_id in Hacs().common.skip:
Hacs().common.skip.remove(repo_id)
if repo_id in hacs.common.skip:
hacs.common.skip.remove(repo_id)
if not Hacs().get_by_name(repo_id):
if not hacs.get_by_name(repo_id):
try:
registration = await Hacs().register_repository(repo_id, data.lower())
registration = await register_repository(repo_id, data.lower())
if registration is not None:
raise HacsException(registration)
except Exception as exception: # pylint: disable=broad-except
@@ -299,15 +307,15 @@ async def hacs_repository_data(hass, connection, msg):
},
)
repository = Hacs().get_by_name(repo_id)
repository = hacs.get_by_name(repo_id)
else:
repository = Hacs().get_by_id(repo_id)
repository = hacs.get_by_id(repo_id)
if repository is None:
hass.bus.async_fire("hacs/repository", {})
return
Hacs().logger.debug(f"Running {action} for {repository.information.full_name}")
hacs.logger.debug(f"Running {action} for {repository.data.full_name}")
if action == "set_state":
repository.state = data
@@ -322,9 +330,9 @@ async def hacs_repository_data(hass, connection, msg):
else:
repository.state = None
Hacs().logger.error(f"WS action '{action}' is not valid")
hacs.logger.error(f"WS action '{action}' is not valid")
await Hacs().data.async_write()
await hacs.data.async_write()
@websocket_api.async_response