fix(devices): SP110E vendor handshake + Windows/bleak robustness
SP110E peripherals silently tear down the GATT link ~1s after connect unless a two-write vendor handshake (01 00 → FFE2, 01 B7 E3 D5 → FFE1) arrives immediately. Without it the first real write hangs 30s then reconnect-loops forever. Adds optional BLEProtocol.init_writes executed on connect, plumbs a per-write char_uuid through both transports, and fixes the SP110E color/power frames from an incorrect 5 bytes to the documented 4 bytes. Windows/WinRT robustness: - asyncio.wait_for hangs on bleak because WinRT IAsyncOperations refuse to cancel. _bounded_await() uses asyncio.wait() instead so timeouts actually return control even when the inner task is uncancellable. - BleakClient connect by raw MAC string times out when WinRT guesses address type wrong; switched to pre-scanning with BleakScanner and passing the resolved BLEDevice, which carries the address type. - Target-start fetch timeout bumped to 30s with retry disabled so the UI doesn't abort during the BLE pre-scan + connect + handshake path. UI: - Settings modal exposes Protocol Family (IconSelect grid, shared with add-device via parameterized ensureBleFamilyIconSelect) so users can fix a wrong family pick without recreating the device. Govee AES key row toggles on/off with family selection. Also turns LAN auth back on in default_config.yaml, logs start_processing requests on entry for easier diagnosis, and captures the full debug trail in docs/BLE_LED_CONTROLLERS.md for future BLE work. Refs the mbullington SP110E protocol gist for the handshake bytes.
This commit is contained in:
@@ -18,24 +18,34 @@ from ledgrab.core.devices.ble_protocols import (
|
||||
|
||||
|
||||
class TestSP110E:
|
||||
def test_color_frame_is_five_bytes_with_cmd_tail(self):
|
||||
def test_color_frame_is_four_bytes_with_cmd_tail(self):
|
||||
frame = sp110e.encode_color(255, 128, 64)
|
||||
assert frame == bytes((255, 128, 64, 0x00, 0x1E))
|
||||
assert frame == bytes((255, 128, 64, 0x1E))
|
||||
|
||||
def test_brightness_scales_rgb(self):
|
||||
frame = sp110e.encode_color(200, 200, 200, brightness=128)
|
||||
# 200 * 128 // 255 == 100
|
||||
assert frame == bytes((100, 100, 100, 0x00, 0x1E))
|
||||
assert frame == bytes((100, 100, 100, 0x1E))
|
||||
|
||||
def test_brightness_255_is_passthrough(self):
|
||||
assert sp110e.encode_color(1, 2, 3, 255) == bytes((1, 2, 3, 0x00, 0x1E))
|
||||
assert sp110e.encode_color(1, 2, 3, 255) == bytes((1, 2, 3, 0x1E))
|
||||
|
||||
def test_clamps_out_of_range(self):
|
||||
assert sp110e.encode_color(-5, 300, 128) == bytes((0, 255, 128, 0x00, 0x1E))
|
||||
assert sp110e.encode_color(-5, 300, 128) == bytes((0, 255, 128, 0x1E))
|
||||
|
||||
def test_power_frames(self):
|
||||
assert sp110e.encode_power(True) == bytes((0, 0, 0, 0, 0xAA))
|
||||
assert sp110e.encode_power(False) == bytes((0, 0, 0, 0, 0xAB))
|
||||
assert sp110e.encode_power(True) == bytes((0, 0, 0, 0xAA))
|
||||
assert sp110e.encode_power(False) == bytes((0, 0, 0, 0xAB))
|
||||
|
||||
def test_init_handshake_is_defined(self):
|
||||
# SP110E silently drops the GATT link within ~1s of connect unless
|
||||
# this two-write handshake arrives — see module docstring.
|
||||
assert len(sp110e.PROTOCOL.init_writes) == 2
|
||||
(ffe2_uuid, ffe2_payload), (ffe1_uuid, ffe1_payload) = sp110e.PROTOCOL.init_writes
|
||||
assert ffe2_uuid.endswith("ffe2-0000-1000-8000-00805f9b34fb") or "ffe2" in ffe2_uuid
|
||||
assert ffe2_payload == b"\x01\x00"
|
||||
assert ffe1_uuid == sp110e.PROTOCOL.write_char_uuid
|
||||
assert ffe1_payload == b"\x01\xb7\xe3\xd5"
|
||||
|
||||
|
||||
class TestTriones:
|
||||
|
||||
Reference in New Issue
Block a user