Add version info to zwave js device diagnostics (#64573)

pull/64581/head
Raman Gupta 2022-01-20 15:55:47 -05:00 committed by GitHub
parent 543064d7b7
commit a420e9443c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 84 deletions

View File

@ -334,7 +334,6 @@ def async_register_api(hass: HomeAssistant) -> None:
hass, websocket_update_data_collection_preference
)
websocket_api.async_register_command(hass, websocket_data_collection_status)
websocket_api.async_register_command(hass, websocket_version_info)
websocket_api.async_register_command(hass, websocket_abort_firmware_update)
websocket_api.async_register_command(
hass, websocket_subscribe_firmware_update_status
@ -1752,35 +1751,6 @@ async def websocket_data_collection_status(
connection.send_result(msg[ID], result)
@websocket_api.require_admin
@websocket_api.websocket_command(
{
vol.Required(TYPE): "zwave_js/version_info",
vol.Required(ENTRY_ID): str,
},
)
@websocket_api.async_response
@async_get_entry
async def websocket_version_info(
hass: HomeAssistant,
connection: ActiveConnection,
msg: dict,
entry: ConfigEntry,
client: Client,
) -> None:
"""Get version info from the Z-Wave JS server."""
version_info = {
"driver_version": client.version.driver_version,
"server_version": client.version.server_version,
"min_schema_version": client.version.min_schema_version,
"max_schema_version": client.version.max_schema_version,
}
connection.send_result(
msg[ID],
version_info,
)
@websocket_api.require_admin
@websocket_api.websocket_command(
{

View File

@ -35,4 +35,15 @@ async def async_get_device_diagnostics(
if node_id is None or node_id not in client.driver.controller.nodes:
raise ValueError(f"Node for device {device.id} can't be found")
node = client.driver.controller.nodes[node_id]
return {**node.data, "values": [value.data for value in node.values.values()]}
return {
"versionInfo": {
"driverVersion": client.version.driver_version,
"serverVersion": client.version.server_version,
"minSchemaVersion": client.version.min_schema_version,
"maxSchemaVersion": client.version.max_schema_version,
},
"state": {
**node.data,
"values": [value.data for value in node.values.values()],
},
}

View File

@ -2716,57 +2716,6 @@ async def test_get_config_parameters(hass, multisensor_6, integration, hass_ws_c
assert msg["error"]["code"] == ERR_NOT_LOADED
async def test_version_info(hass, integration, hass_ws_client, version_state):
"""Test version info API request."""
entry = integration
ws_client = await hass_ws_client(hass)
version_info = {
"driver_version": version_state["driverVersion"],
"server_version": version_state["serverVersion"],
"min_schema_version": 0,
"max_schema_version": 0,
}
await ws_client.send_json(
{
ID: 3,
TYPE: "zwave_js/version_info",
ENTRY_ID: entry.entry_id,
}
)
msg = await ws_client.receive_json()
assert msg["result"] == version_info
# Test getting non-existent entry fails
await ws_client.send_json(
{
ID: 4,
TYPE: "zwave_js/version_info",
ENTRY_ID: "INVALID",
}
)
msg = await ws_client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == ERR_NOT_FOUND
# Test sending command with not loaded entry fails
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
await ws_client.send_json(
{
ID: 5,
TYPE: "zwave_js/version_info",
ENTRY_ID: entry.entry_id,
}
)
msg = await ws_client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == ERR_NOT_LOADED
async def test_firmware_upload_view(
hass, multisensor_6, integration, hass_client, firmware_file
):

View File

@ -35,6 +35,7 @@ async def test_device_diagnostics(
multisensor_6,
integration,
hass_client,
version_state,
):
"""Test the device level diagnostics data dump."""
dev_reg = async_get(hass)
@ -67,9 +68,15 @@ async def test_device_diagnostics(
diagnostics_data = await get_diagnostics_for_device(
hass, hass_client, integration, device
)
assert diagnostics_data["versionInfo"] == {
"driverVersion": version_state["driverVersion"],
"serverVersion": version_state["serverVersion"],
"minSchemaVersion": 0,
"maxSchemaVersion": 0,
}
# Assert that the data returned doesn't match the stale node state data
assert diagnostics_data != multisensor_6.data
assert diagnostics_data["state"] != multisensor_6.data
# Replace data for the value we updated and assert the new node data is the same
# as what's returned
@ -79,7 +86,7 @@ async def test_device_diagnostics(
updated_node_data["values"][idx] = multisensor_6.values[
value_id
].data.copy()
assert diagnostics_data == updated_node_data
assert diagnostics_data["state"] == updated_node_data
async def test_device_diagnostics_error(hass, integration):