Files
led-controller/tests/test_bridge_ws_client.py
Jimmy cfdd6de291 docs(espnow): update docs and tests for p2p merge
Align API, architecture, and help with devices envelope transport,
bridge wifi/serial settings, and MAC-keyed device registry. Fix
endpoint tests for envelope identify payloads; remove obsolete p2p.py.
Bump led-tool for --serial-usb bridge provisioning.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 21:10:06 +12:00

37 lines
1012 B
Python

#!/usr/bin/env python3
"""Tests for bridge WebSocket client reconnect behaviour."""
from __future__ import annotations
import asyncio
import sys
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
from models.bridge_ws_client import BridgeWsClient # noqa: E402
def test_send_returns_false_when_not_connected():
async def _run():
client = BridgeWsClient("ws://127.0.0.1/ws", reconnect_delay_s=0.01)
async def _no_wait(timeout=30.0):
return False
client.wait_connected = _no_wait # type: ignore[method-assign]
return await client.send_packet({"v": "1", "devices": {}})
assert asyncio.run(_run()) is False
def test_disconnect_clears_connected_event():
client = BridgeWsClient("ws://127.0.0.1/ws", reconnect_delay_s=0.01)
client._connected.set()
client._signal_disconnect()
assert not client._connected.is_set()