mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 21:25:13 +02:00
Add websocket command to get a list of OZW instances and their status (#39019)
* Add websocket command to get a list of OZW instances and their status * Add test * Review comments
This commit is contained in:
@@ -21,6 +21,7 @@ NODE_ID = "node_id"
|
|||||||
@callback
|
@callback
|
||||||
def async_register_api(hass):
|
def async_register_api(hass):
|
||||||
"""Register all of our api endpoints."""
|
"""Register all of our api endpoints."""
|
||||||
|
websocket_api.async_register_command(hass, websocket_get_instances)
|
||||||
websocket_api.async_register_command(hass, websocket_network_status)
|
websocket_api.async_register_command(hass, websocket_network_status)
|
||||||
websocket_api.async_register_command(hass, websocket_node_metadata)
|
websocket_api.async_register_command(hass, websocket_node_metadata)
|
||||||
websocket_api.async_register_command(hass, websocket_node_status)
|
websocket_api.async_register_command(hass, websocket_node_status)
|
||||||
@@ -28,6 +29,20 @@ def async_register_api(hass):
|
|||||||
websocket_api.async_register_command(hass, websocket_refresh_node_info)
|
websocket_api.async_register_command(hass, websocket_refresh_node_info)
|
||||||
|
|
||||||
|
|
||||||
|
@websocket_api.websocket_command({vol.Required(TYPE): "ozw/get_instances"})
|
||||||
|
def websocket_get_instances(hass, connection, msg):
|
||||||
|
"""Get a list of OZW instances."""
|
||||||
|
manager = hass.data[DOMAIN][MANAGER]
|
||||||
|
instances = []
|
||||||
|
|
||||||
|
for instance in manager.collections["instance"]:
|
||||||
|
instances.append(dict(instance.get_status().data, id=instance.id))
|
||||||
|
|
||||||
|
connection.send_result(
|
||||||
|
msg[ID], instances,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.websocket_command(
|
@websocket_api.websocket_command(
|
||||||
{
|
{
|
||||||
vol.Required(TYPE): "ozw/network_status",
|
vol.Required(TYPE): "ozw/network_status",
|
||||||
|
@@ -12,6 +12,15 @@ async def test_websocket_api(hass, generic_data, hass_ws_client):
|
|||||||
await setup_ozw(hass, fixture=generic_data)
|
await setup_ozw(hass, fixture=generic_data)
|
||||||
client = await hass_ws_client(hass)
|
client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
# Test instance list
|
||||||
|
await client.send_json({ID: 4, TYPE: "ozw/get_instances"})
|
||||||
|
msg = await client.receive_json()
|
||||||
|
assert len(msg["result"]) == 1
|
||||||
|
result = msg["result"][0]
|
||||||
|
assert result["id"] == 1
|
||||||
|
assert result["Status"] == "driverAllNodesQueried"
|
||||||
|
assert result["OpenZWave_Version"] == "1.6.1008"
|
||||||
|
|
||||||
# Test network status
|
# Test network status
|
||||||
await client.send_json({ID: 5, TYPE: "ozw/network_status"})
|
await client.send_json({ID: 5, TYPE: "ozw/network_status"})
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
|
Reference in New Issue
Block a user