Guard zwave_js missing nodes in websocket api (#47096)
parent
6e77ca70fc
commit
d8633f94f6
|
@ -106,7 +106,12 @@ def websocket_node_status(
|
||||||
entry_id = msg[ENTRY_ID]
|
entry_id = msg[ENTRY_ID]
|
||||||
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
||||||
node_id = msg[NODE_ID]
|
node_id = msg[NODE_ID]
|
||||||
node = client.driver.controller.nodes[node_id]
|
node = client.driver.controller.nodes.get(node_id)
|
||||||
|
|
||||||
|
if node is None:
|
||||||
|
connection.send_error(msg[ID], ERR_NOT_FOUND, f"Node {node_id} not found")
|
||||||
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"node_id": node.node_id,
|
"node_id": node.node_id,
|
||||||
"is_routing": node.is_routing,
|
"is_routing": node.is_routing,
|
||||||
|
@ -354,7 +359,12 @@ def websocket_get_config_parameters(
|
||||||
entry_id = msg[ENTRY_ID]
|
entry_id = msg[ENTRY_ID]
|
||||||
node_id = msg[NODE_ID]
|
node_id = msg[NODE_ID]
|
||||||
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
||||||
node = client.driver.controller.nodes[node_id]
|
node = client.driver.controller.nodes.get(node_id)
|
||||||
|
|
||||||
|
if node is None:
|
||||||
|
connection.send_error(msg[ID], ERR_NOT_FOUND, f"Node {node_id} not found")
|
||||||
|
return
|
||||||
|
|
||||||
values = node.get_configuration_values()
|
values = node.get_configuration_values()
|
||||||
result = {}
|
result = {}
|
||||||
for value_id, zwave_value in values.items():
|
for value_id, zwave_value in values.items():
|
||||||
|
|
|
@ -6,6 +6,7 @@ from zwave_js_server.const import LogLevel
|
||||||
from zwave_js_server.event import Event
|
from zwave_js_server.event import Event
|
||||||
from zwave_js_server.exceptions import InvalidNewValue, NotFoundError, SetValueFailed
|
from zwave_js_server.exceptions import InvalidNewValue, NotFoundError, SetValueFailed
|
||||||
|
|
||||||
|
from homeassistant.components.websocket_api.const import ERR_NOT_FOUND
|
||||||
from homeassistant.components.zwave_js.api import (
|
from homeassistant.components.zwave_js.api import (
|
||||||
CONFIG,
|
CONFIG,
|
||||||
ENABLED,
|
ENABLED,
|
||||||
|
@ -76,6 +77,32 @@ async def test_websocket_api(hass, integration, multisensor_6, hass_ws_client):
|
||||||
assert result[key]["configuration_value_type"] == "enumerated"
|
assert result[key]["configuration_value_type"] == "enumerated"
|
||||||
assert result[key]["metadata"]["states"]
|
assert result[key]["metadata"]["states"]
|
||||||
|
|
||||||
|
# Test getting non-existent node fails
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 5,
|
||||||
|
TYPE: "zwave_js/node_status",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
NODE_ID: 99999,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == ERR_NOT_FOUND
|
||||||
|
|
||||||
|
# Test getting non-existent node config params fails
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 6,
|
||||||
|
TYPE: "zwave_js/get_config_parameters",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
NODE_ID: 99999,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == ERR_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
async def test_add_node(
|
async def test_add_node(
|
||||||
hass, integration, client, hass_ws_client, nortek_thermostat_added_event
|
hass, integration, client, hass_ws_client, nortek_thermostat_added_event
|
||||||
|
|
Loading…
Reference in New Issue