Add WebSocket API Foundation for zwave_js (#45151)

This commit is contained in:
Charles Garwood
2021-01-15 15:17:40 +01:00
committed by GitHub
parent 071c8cc67d
commit 9dbf14188a
4 changed files with 91 additions and 1 deletions
+17 -1
View File
@@ -5,6 +5,7 @@ from unittest.mock import DEFAULT, patch
import pytest
from zwave_js_server.model.driver import Driver
from zwave_js_server.model.node import Node
from zwave_js_server.version import VersionInfo
from homeassistant.helpers.device_registry import (
async_get_registry as async_get_device_registry,
@@ -25,6 +26,17 @@ def controller_state_fixture():
return json.loads(load_fixture("zwave_js/controller_state.json"))
@pytest.fixture(name="version_state", scope="session")
def version_state_fixture():
"""Load the version state fixture data."""
return {
"type": "version",
"driverVersion": "6.0.0-beta.0",
"serverVersion": "1.0.0",
"homeId": 1234567890,
}
@pytest.fixture(name="multisensor_6_state", scope="session")
def multisensor_6_state_fixture():
"""Load the multisensor 6 node state fixture data."""
@@ -50,13 +62,17 @@ def bulb_6_multi_color_state_fixture():
@pytest.fixture(name="client")
def mock_client_fixture(controller_state):
def mock_client_fixture(controller_state, version_state):
"""Mock a client."""
with patch(
"homeassistant.components.zwave_js.ZwaveClient", autospec=True
) as client_class:
driver = Driver(client_class.return_value, controller_state)
version = VersionInfo.from_message(version_state)
client_class.return_value.driver = driver
client_class.return_value.version = version
client_class.return_value.ws_server_url = "ws://test:3000/zjs"
client_class.return_value.state = "connected"
yield client_class.return_value
@@ -0,0 +1,18 @@
"""Test the Z-Wave JS Websocket API."""
from homeassistant.components.zwave_js.websocket_api import ENTRY_ID, ID, TYPE
async def test_websocket_api(hass, integration, hass_ws_client):
"""Test the network_status websocket command."""
entry = integration
ws_client = await hass_ws_client(hass)
await ws_client.send_json(
{ID: 2, TYPE: "zwave_js/network_status", ENTRY_ID: entry.entry_id}
)
msg = await ws_client.receive_json()
result = msg["result"]
assert result["client"]["ws_server_url"] == "ws://test:3000/zjs"
assert result["client"]["server_version"] == "1.0.0"