Add websocket command to set preferred thread dataset (#89700)
This commit is contained in:
parent
73e1942eeb
commit
a213ef2475
2 changed files with 76 additions and 0 deletions
|
@ -20,6 +20,7 @@ def async_setup(hass: HomeAssistant) -> None:
|
|||
websocket_api.async_register_command(hass, ws_discover_routers)
|
||||
websocket_api.async_register_command(hass, ws_get_dataset)
|
||||
websocket_api.async_register_command(hass, ws_list_datasets)
|
||||
websocket_api.async_register_command(hass, ws_set_preferred_dataset)
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
|
@ -49,6 +50,31 @@ async def ws_add_dataset(
|
|||
connection.send_result(msg["id"])
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): "thread/set_preferred_dataset",
|
||||
vol.Required("dataset_id"): str,
|
||||
}
|
||||
)
|
||||
@websocket_api.async_response
|
||||
async def ws_set_preferred_dataset(
|
||||
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Add a thread dataset."""
|
||||
dataset_id = msg["dataset_id"]
|
||||
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
if not (store.async_get(dataset_id)):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "unknown dataset"
|
||||
)
|
||||
return
|
||||
|
||||
store.preferred_dataset = dataset_id
|
||||
connection.send_result(msg["id"])
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue