async def test_check_ws_initial(protect_client: ProtectApiClient, caplog: pytest.LogCaptureFixture): caplog.set_level(logging.DEBUG) protect_client._last_websocket_check = NEVER_RAN protect_client.reset_ws() active_ws = await protect_client.check_ws() assert active_ws is True assert ["Checking websocket"] == [rec.message for rec in caplog.records]
async def test_check_ws_no_ws(protect_client: ProtectApiClient, caplog: pytest.LogCaptureFixture): caplog.set_level(logging.DEBUG) protect_client._last_websocket_check = time.monotonic() protect_client.reset_ws() active_ws = await protect_client.check_ws() assert active_ws is False expected_logs = [ "Unifi OS: Websocket connection not active, failing back to polling" ] assert expected_logs == [rec.message for rec in caplog.records] assert caplog.records[0].levelname == "DEBUG"
async def test_check_ws_reconnect(protect_client: ProtectApiClient, caplog: pytest.LogCaptureFixture): caplog.set_level(logging.DEBUG) protect_client._last_websocket_check = time.monotonic( ) - WEBSOCKET_CHECK_INTERVAL - 1 protect_client.reset_ws() active_ws = await protect_client.check_ws() assert active_ws is True expected_logs = [ "Checking websocket", "Unifi OS: Websocket connection not active, failing back to polling" ] assert expected_logs == [rec.message for rec in caplog.records] assert caplog.records[1].levelname == "WARNING"