Add WS commands thread/list_datasets, thread/get_dataset_tlv (#87333)
This commit is contained in:
parent
04b921e3b5
commit
6f097eecc3
4 changed files with 203 additions and 9 deletions
|
@ -16,6 +16,8 @@ from . import dataset_store
|
|||
def async_setup(hass: HomeAssistant) -> None:
|
||||
"""Set up the sensor websocket API."""
|
||||
websocket_api.async_register_command(hass, ws_add_dataset)
|
||||
websocket_api.async_register_command(hass, ws_get_dataset)
|
||||
websocket_api.async_register_command(hass, ws_list_datasets)
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
|
@ -43,3 +45,57 @@ async def ws_add_dataset(
|
|||
return
|
||||
|
||||
connection.send_result(msg["id"])
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): "thread/get_dataset_tlv",
|
||||
vol.Required("dataset_id"): str,
|
||||
}
|
||||
)
|
||||
@websocket_api.async_response
|
||||
async def ws_get_dataset(
|
||||
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Get a thread dataset in TLV format."""
|
||||
dataset_id = msg["dataset_id"]
|
||||
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
if not (dataset := store.async_get(dataset_id)):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "unknown dataset"
|
||||
)
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"], {"tlv": dataset.tlv})
|
||||
|
||||
|
||||
@websocket_api.require_admin
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): "thread/list_datasets",
|
||||
}
|
||||
)
|
||||
@websocket_api.async_response
|
||||
async def ws_list_datasets(
|
||||
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Get a list of thread datasets."""
|
||||
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
result = []
|
||||
for dataset in store.datasets.values():
|
||||
result.append(
|
||||
{
|
||||
"created": dataset.created,
|
||||
"dataset_id": dataset.id,
|
||||
"extended_pan_id": dataset.extended_pan_id,
|
||||
"network_name": dataset.network_name,
|
||||
"pan_id": dataset.pan_id,
|
||||
"preferred": dataset.preferred,
|
||||
"source": dataset.source,
|
||||
}
|
||||
)
|
||||
|
||||
connection.send_result(msg["id"], {"datasets": result})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue