feat(pm3py): LED API with color names and keyword actions (on/off/pulse/fade/blink/brightness)

This commit is contained in:
michael
2026-03-16 00:13:50 -07:00
parent 29bfccfb41
commit 8cce7eeba3
2 changed files with 101 additions and 9 deletions

View File

@@ -39,9 +39,36 @@ def test_status():
result = asyncio.get_event_loop().run_until_complete(hw.status())
assert result["status"] == 0
def test_led():
def test_led_on_by_name():
transport = make_mock_transport()
hw = HWCommands(transport)
transport.send_ng.return_value = make_ng_response(Cmd.LED_CONTROL, 0, b"")
result = asyncio.get_event_loop().run_until_complete(hw.led(1, "on"))
result = asyncio.get_event_loop().run_until_complete(hw.led("green", on=True))
transport.send_ng.assert_called_once()
def test_led_pulse():
transport = make_mock_transport()
hw = HWCommands(transport)
transport.send_ng.return_value = make_ng_response(Cmd.LED_CONTROL, 0, b"")
result = asyncio.get_event_loop().run_until_complete(
hw.led("red", pulse=True, speed=300, count=3))
transport.send_ng.assert_called_once()
# Verify the payload
call_args = transport.send_ng.call_args
payload = call_args[0][1] # second positional arg
led_mask, action, brightness, speed, count = struct.unpack("<BBBHH", payload)
assert led_mask == 0x04 # red = C
assert action == 4 # pulse
assert speed == 300
assert count == 3
def test_led_brightness():
transport = make_mock_transport()
hw = HWCommands(transport)
transport.send_ng.return_value = make_ng_response(Cmd.LED_CONTROL, 0, b"")
result = asyncio.get_event_loop().run_until_complete(hw.led("all", brightness=50))
payload = transport.send_ng.call_args[0][1]
led_mask, action, bright, _, _ = struct.unpack("<BBBHH", payload)
assert led_mask == 0x0F # all
assert action == 3 # pwm
assert bright == 50