Add MockHAClientWebSocket test helper (#87832)
* Add MockHAClientWebSocket test helper * Add sample use * Add missing type hint
This commit is contained in:
parent
0cf5e9fb4a
commit
6a1cd75a67
3 changed files with 31 additions and 9 deletions
|
@ -30,20 +30,20 @@ async def test_websocket(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
await ws_client.send_json({"id": 1, "type": "analytics"})
|
||||
await ws_client.send_json_auto_id({"type": "analytics"})
|
||||
|
||||
response = await ws_client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
|
||||
with patch("homeassistant.components.analytics.analytics.HA_VERSION", MOCK_VERSION):
|
||||
await ws_client.send_json(
|
||||
{"id": 2, "type": "analytics/preferences", "preferences": {"base": True}}
|
||||
await ws_client.send_json_auto_id(
|
||||
{"type": "analytics/preferences", "preferences": {"base": True}}
|
||||
)
|
||||
response = await ws_client.receive_json()
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert response["result"]["preferences"]["base"]
|
||||
|
||||
await ws_client.send_json({"id": 3, "type": "analytics"})
|
||||
await ws_client.send_json_auto_id({"type": "analytics"})
|
||||
response = await ws_client.receive_json()
|
||||
assert response["result"]["preferences"]["base"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue