Send presets and select on broadcast with groups; unicast only for per-device settings. V1 select as [preset_id, step?]. Sequence steps use beat counts; manual presets get select each beat, auto only on step change. Bridge downlink router, Pi envelope delivery, and tests. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1013 B
Python
37 lines
1013 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()
|