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
|
@ -5,7 +5,7 @@ from homeassistant.components.thread.const import DOMAIN
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import DATASET_1
|
||||
from . import DATASET_1, DATASET_2, DATASET_3
|
||||
|
||||
|
||||
async def test_add_dataset(hass: HomeAssistant, hass_ws_client) -> None:
|
||||
|
@ -22,7 +22,7 @@ async def test_add_dataset(hass: HomeAssistant, hass_ws_client) -> None:
|
|||
assert msg["success"]
|
||||
assert msg["result"] is None
|
||||
|
||||
store = await dataset_store._async_get_store(hass)
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
assert len(store.datasets) == 1
|
||||
dataset = next(iter(store.datasets.values()))
|
||||
assert dataset.source == "test"
|
||||
|
@ -42,3 +42,82 @@ async def test_add_invalid_dataset(hass: HomeAssistant, hass_ws_client) -> None:
|
|||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {"code": "invalid_format", "message": "unknown type 222"}
|
||||
|
||||
|
||||
async def test_list_get_dataset(hass: HomeAssistant, hass_ws_client) -> None:
|
||||
"""Test list and get datasets."""
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json({"id": 1, "type": "thread/list_datasets"})
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == {"datasets": []}
|
||||
|
||||
datasets = [
|
||||
{"source": "Google", "tlv": DATASET_1},
|
||||
{"source": "Multipan", "tlv": DATASET_2},
|
||||
{"source": "🎅", "tlv": DATASET_3},
|
||||
]
|
||||
for dataset in datasets:
|
||||
await dataset_store.async_add_dataset(hass, dataset["source"], dataset["tlv"])
|
||||
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
for dataset in store.datasets.values():
|
||||
if dataset.source == "Google":
|
||||
dataset_1 = dataset
|
||||
if dataset.source == "Multipan":
|
||||
dataset_2 = dataset
|
||||
if dataset.source == "🎅":
|
||||
dataset_3 = dataset
|
||||
|
||||
await client.send_json({"id": 2, "type": "thread/list_datasets"})
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == {
|
||||
"datasets": [
|
||||
{
|
||||
"created": dataset_1.created.isoformat(),
|
||||
"dataset_id": dataset_1.id,
|
||||
"extended_pan_id": "1111111122222222",
|
||||
"network_name": "OpenThreadDemo",
|
||||
"pan_id": "1234",
|
||||
"preferred": True,
|
||||
"source": "Google",
|
||||
},
|
||||
{
|
||||
"created": dataset_2.created.isoformat(),
|
||||
"dataset_id": dataset_2.id,
|
||||
"extended_pan_id": "1111111122222222",
|
||||
"network_name": "HomeAssistant!",
|
||||
"pan_id": "1234",
|
||||
"preferred": False,
|
||||
"source": "Multipan",
|
||||
},
|
||||
{
|
||||
"created": dataset_3.created.isoformat(),
|
||||
"dataset_id": dataset_3.id,
|
||||
"extended_pan_id": "1111111122222222",
|
||||
"network_name": "~🐣🐥🐤~",
|
||||
"pan_id": "1234",
|
||||
"preferred": False,
|
||||
"source": "🎅",
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
await client.send_json(
|
||||
{"id": 3, "type": "thread/get_dataset_tlv", "dataset_id": dataset_2.id}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == {"tlv": dataset_2.tlv}
|
||||
|
||||
await client.send_json(
|
||||
{"id": 4, "type": "thread/get_dataset_tlv", "dataset_id": "blah"}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {"code": "not_found", "message": "unknown dataset"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue