1 """Dynalite API interface for the frontend."""
3 from dynalite_panel
import get_build_id, locate_dir
4 import voluptuous
as vol
23 from .schema
import BRIDGE_SCHEMA
25 URL_BASE =
"/dynalite_static"
40 @websocket_api.websocket_command(
{
vol.Required("type"):
"dynalite/get-config",
43 @websocket_api.require_admin
48 """Retrieve the Dynalite config for the frontend."""
49 entries = hass.config_entries.async_entries(DOMAIN)
52 conf: entry.data[conf]
for conf
in RELEVANT_CONFS
if conf
in entry.data
57 "DEFAULT_NAME": DEFAULT_NAME,
58 "DEVICE_CLASSES": DEVICE_CLASSES,
59 "DEFAULT_PORT": DEFAULT_PORT,
61 connection.send_result(
62 msg[
"id"], {
"config": relevant_config,
"default": dynalite_defaults}
66 @websocket_api.websocket_command(
{
vol.Required("type"):
"dynalite/save-config",
67 vol.Required(
"entry_id"): str,
68 vol.Required(
"config"): BRIDGE_SCHEMA,
71 @websocket_api.require_admin
76 """Retrieve the Dynalite config for the frontend."""
77 entry_id = msg[
"entry_id"]
78 entry = hass.config_entries.async_get_entry(entry_id)
81 "Dynalite - received updated config for invalid entry - %s", entry_id
83 connection.send_result(msg[
"id"], {
"error":
True})
85 message_conf = msg[
"config"]
87 conf: message_conf[conf]
for conf
in RELEVANT_CONFS
if conf
in message_conf
89 LOGGER.debug(
"Updating Dynalite config entry")
90 hass.config_entries.async_update_entry(entry, data=message_data)
91 connection.send_result(msg[
"id"], {})
95 """Register the Dynalite frontend configuration panel."""
96 websocket_api.async_register_command(hass, get_dynalite_config)
97 websocket_api.async_register_command(hass, save_dynalite_config)
99 build_id = get_build_id()
100 await hass.http.async_register_static_paths(
104 await panel_custom.async_register_panel(
106 frontend_url_path=DOMAIN,
107 config_panel_domain=DOMAIN,
108 webcomponent_name=
"dynalite-panel",
109 module_url=f
"{URL_BASE}/entrypoint-{build_id}.js",
113
None save_dynalite_config(HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
None get_dynalite_config(HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
def async_register_dynalite_frontend(HomeAssistant hass)