mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-15 05:50:16 +00:00
Initial WS support (#2439)
* Initial WS support * test * Update frontend to fc7c4af2 * Fix issue with closing states * log error * make data optional * limit stopping states * Move wrappers to HomeAssistantWebSocket * use info * Use call_soon * Use lookuptable for WS commands * Fix tests
This commit is contained in:
49
tests/homeassistant/test_websocket.py
Normal file
49
tests/homeassistant/test_websocket.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Test websocket."""
|
||||
# pylint: disable=protected-access, import-error
|
||||
import logging
|
||||
|
||||
from awesomeversion import AwesomeVersion
|
||||
|
||||
from supervisor.coresys import CoreSys
|
||||
|
||||
|
||||
async def test_send_command(coresys: CoreSys):
|
||||
"""Test websocket error on listen."""
|
||||
client = coresys.homeassistant.websocket._client
|
||||
await coresys.homeassistant.websocket.async_send_command({"type": "test"})
|
||||
client.async_send_command.assert_called_with({"type": "test"})
|
||||
|
||||
await coresys.homeassistant.websocket.async_supervisor_update_event(
|
||||
"test", {"lorem": "ipsum"}
|
||||
)
|
||||
client.async_send_command.assert_called_with(
|
||||
{
|
||||
"type": "supervisor/event",
|
||||
"data": {
|
||||
"event": "supervisor-update",
|
||||
"update_key": "test",
|
||||
"data": {"lorem": "ipsum"},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def test_send_command_old_core_version(coresys: CoreSys, caplog):
|
||||
"""Test websocket error on listen."""
|
||||
caplog.set_level(logging.INFO)
|
||||
client = coresys.homeassistant.websocket._client
|
||||
client.ha_version = AwesomeVersion("1970.1.1")
|
||||
|
||||
await coresys.homeassistant.websocket.async_send_command(
|
||||
{"type": "supervisor/event"}
|
||||
)
|
||||
|
||||
assert (
|
||||
"WebSocket command supervisor/event is not supported untill core-2021.2.4"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
await coresys.homeassistant.websocket.async_supervisor_update_event(
|
||||
"test", {"lorem": "ipsum"}
|
||||
)
|
||||
client.async_send_command.assert_not_called()
|
||||
Reference in New Issue
Block a user