Separate startup event from update check event (#4425)

* Separate startup event from update check event

* Add a queue for messages sent during startup
This commit is contained in:
Mike Degatano
2023-07-06 12:45:37 -04:00
committed by GitHub
parent 3b38047fd4
commit 96d5fc244e
6 changed files with 105 additions and 6 deletions

View File

@@ -1,9 +1,11 @@
"""Test websocket."""
# pylint: disable=protected-access, import-error
import asyncio
import logging
from awesomeversion import AwesomeVersion
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.homeassistant.const import WSEvent, WSType
@@ -48,3 +50,36 @@ async def test_send_command_old_core_version(coresys: CoreSys, caplog):
"test", {"lorem": "ipsum"}
)
client.async_send_command.assert_not_called()
async def test_send_message_during_startup(coresys: CoreSys):
"""Test websocket messages queue during startup."""
client = coresys.homeassistant.websocket._client
await coresys.homeassistant.websocket.load()
coresys.core.state = CoreState.SETUP
await coresys.homeassistant.websocket.async_supervisor_update_event(
"test", {"lorem": "ipsum"}
)
client.async_send_command.assert_not_called()
coresys.core.state = CoreState.RUNNING
await asyncio.sleep(0)
assert client.async_send_command.call_count == 2
assert client.async_send_command.call_args_list[0][0][0] == {
"type": WSType.SUPERVISOR_EVENT,
"data": {
"event": WSEvent.SUPERVISOR_UPDATE,
"update_key": "test",
"data": {"lorem": "ipsum"},
},
}
assert client.async_send_command.call_args_list[1][0][0] == {
"type": WSType.SUPERVISOR_EVENT,
"data": {
"event": WSEvent.SUPERVISOR_UPDATE,
"update_key": "info",
"data": {"state": "running"},
},
}