updated lovelace dashboards and migrate tcp sensors to use serial component with SOCAT
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Register_commands."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
@@ -24,6 +25,7 @@ from .repository import (
|
||||
hacs_repository_info,
|
||||
hacs_repository_refresh,
|
||||
hacs_repository_release_notes,
|
||||
hacs_repository_releases,
|
||||
hacs_repository_remove,
|
||||
hacs_repository_state,
|
||||
hacs_repository_version,
|
||||
@@ -57,6 +59,7 @@ def async_register_websocket_commands(hass: HomeAssistant) -> None:
|
||||
websocket_api.async_register_command(hass, hacs_repositories_clear_new)
|
||||
websocket_api.async_register_command(hass, hacs_repositories_removed)
|
||||
websocket_api.async_register_command(hass, hacs_repositories_remove)
|
||||
websocket_api.async_register_command(hass, hacs_repository_releases)
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
@@ -75,7 +78,7 @@ async def hacs_subscribe(
|
||||
"""Handle websocket subscriptions."""
|
||||
|
||||
@callback
|
||||
def forward_messages(data: dict | None = None):
|
||||
def forward_messages(data: dict | None = None) -> None:
|
||||
"""Forward events to websocket."""
|
||||
connection.send_message(websocket_api.event_message(msg["id"], data))
|
||||
|
||||
@@ -110,7 +113,6 @@ async def hacs_info(
|
||||
"debug": hacs.configuration.debug,
|
||||
"dev": hacs.configuration.dev,
|
||||
"disabled_reason": hacs.system.disabled_reason,
|
||||
"experimental": hacs.configuration.experimental,
|
||||
"has_pending_tasks": hacs.queue.has_pending_tasks,
|
||||
"lovelace_mode": hacs.core.lovelace_mode,
|
||||
"stage": hacs.stage,
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
"""Register info websocket commands."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
from ..utils.store import async_load_from_store, async_save_to_store
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
@@ -22,7 +25,7 @@ async def hacs_critical_list(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""List critical repositories."""
|
||||
connection.send_message(
|
||||
websocket_api.result_message(
|
||||
@@ -44,7 +47,7 @@ async def hacs_critical_acknowledge(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Acknowledge critical repository."""
|
||||
repository = msg["repository"]
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"""Register info websocket commands."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -15,6 +15,8 @@ from ..const import DOMAIN
|
||||
from ..enums import HacsDispatchEvent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from ..base import HacsBase
|
||||
|
||||
|
||||
@@ -30,7 +32,7 @@ async def hacs_repositories_list(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""List repositories."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
connection.send_message(
|
||||
@@ -68,7 +70,7 @@ async def hacs_repositories_list(
|
||||
for repo in hacs.repositories.list_all
|
||||
if repo.data.category in msg.get("categories", hacs.common.categories)
|
||||
and not repo.ignored_by_country_configuration
|
||||
and (not hacs.configuration.experimental or repo.data.last_fetched)
|
||||
and repo.data.last_fetched
|
||||
],
|
||||
)
|
||||
)
|
||||
@@ -88,7 +90,7 @@ async def hacs_repositories_clear_new(
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
) -> None:
|
||||
"""Clear new repositories for spesific categories."""
|
||||
"""Clear new repositories for specific categories."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
|
||||
if repo := msg.get("repository"):
|
||||
@@ -119,7 +121,7 @@ async def hacs_repositories_removed(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Get information about removed repositories."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
content = []
|
||||
@@ -142,7 +144,7 @@ async def hacs_repositories_add(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Add custom repositoriy."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = regex.extract_repository_from_url(msg["repository"])
|
||||
@@ -203,7 +205,7 @@ async def hacs_repositories_remove(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Remove custom repositoriy."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
"""Register info websocket commands."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
from ..const import DOMAIN
|
||||
from ..enums import HacsDispatchEvent
|
||||
from ..exceptions import HacsException
|
||||
from ..utils.version import version_left_higher_then_right
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from ..base import HacsBase
|
||||
|
||||
|
||||
@@ -107,7 +110,7 @@ async def hacs_repository_ignore(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Ignore a repository."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository_id = msg["repository"]
|
||||
@@ -140,7 +143,7 @@ async def hacs_repository_state(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Set the state of a repository"""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
@@ -164,7 +167,7 @@ async def hacs_repository_version(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Set the version of a repository"""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
@@ -194,7 +197,7 @@ async def hacs_repository_beta(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Show or hide beta versions of a repository"""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
@@ -221,24 +224,23 @@ async def hacs_repository_download(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Set the version of a repository"""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
|
||||
was_installed = repository.data.installed
|
||||
if version := msg.get("version"):
|
||||
repository.data.selected_tag = version
|
||||
await repository.update_repository(force=True)
|
||||
try:
|
||||
was_installed = repository.data.installed
|
||||
await repository.async_download_repository(ref=msg.get("version"))
|
||||
if not was_installed:
|
||||
hacs.async_dispatch(HacsDispatchEvent.RELOAD, {"force": True})
|
||||
await hacs.async_recreate_entities()
|
||||
|
||||
await repository.async_install()
|
||||
repository.state = None
|
||||
if not was_installed:
|
||||
hacs.async_dispatch(HacsDispatchEvent.RELOAD, {"force": True})
|
||||
await hacs.async_recreate_entities()
|
||||
|
||||
await hacs.data.async_write()
|
||||
connection.send_message(websocket_api.result_message(msg["id"], {}))
|
||||
await hacs.data.async_write()
|
||||
connection.send_message(websocket_api.result_message(msg["id"], {}))
|
||||
except HacsException as exception:
|
||||
repository.logger.error("%s %s", repository.string, exception)
|
||||
connection.send_error(msg["id"], "error", str(exception))
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
@@ -253,7 +255,7 @@ async def hacs_repository_remove(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Remove a repository."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
@@ -281,13 +283,15 @@ async def hacs_repository_refresh(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Refresh a repository."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
|
||||
await repository.update_repository(ignore_issues=True, force=True)
|
||||
await hacs.data.async_write()
|
||||
# Update state of update entity
|
||||
hacs.coordinators[repository.data.category].async_update_listeners()
|
||||
|
||||
connection.send_message(websocket_api.result_message(msg["id"], {}))
|
||||
|
||||
@@ -304,7 +308,7 @@ async def hacs_repository_release_notes(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
):
|
||||
) -> None:
|
||||
"""Return release notes."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository"])
|
||||
@@ -324,3 +328,42 @@ async def hacs_repository_release_notes(
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): "hacs/repository/releases",
|
||||
vol.Required("repository_id"): cv.string,
|
||||
}
|
||||
)
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.async_response
|
||||
async def hacs_repository_releases(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
) -> None:
|
||||
"""Return releases."""
|
||||
hacs: HacsBase = hass.data.get(DOMAIN)
|
||||
repository = hacs.repositories.get_by_id(msg["repository_id"])
|
||||
try:
|
||||
releases = await repository.async_get_releases()
|
||||
except Exception as exception:
|
||||
hacs.log.exception(exception)
|
||||
connection.send_error(msg["id"], "unknown", str(exception))
|
||||
return
|
||||
|
||||
connection.send_message(
|
||||
websocket_api.result_message(
|
||||
msg["id"],
|
||||
[
|
||||
{
|
||||
"name": release.name,
|
||||
"tag": release.tag_name,
|
||||
"published_at": release.published_at,
|
||||
"prerelease": release.prerelease,
|
||||
}
|
||||
for release in releases
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user