Checks / tests (ubuntu-latest, 3.11) (push) Canceled after 0s
Checks / tests (ubuntu-latest, 3.14) (push) Canceled after 0s
Checks / tests (windows-latest, 3.11) (push) Canceled after 0s
Checks / tests (windows-latest, 3.14) (push) Canceled after 0s
Checks / package (push) Canceled after 0s
51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
"""Human-readable packet meaning, including ACK versus actual state reports."""
|
|
|
|
import unittest
|
|
|
|
from controller.messages import ActivityLog, describe_command, describe_reply
|
|
from controller.protocol import Frame
|
|
|
|
|
|
class MessageTests(unittest.TestCase):
|
|
def test_outgoing_layout_and_rgb(self):
|
|
self.assertEqual(describe_command(bytes.fromhex("40 03 00 05 00")), "Set EQ to Rock")
|
|
self.assertEqual(
|
|
describe_command(bytes.fromhex("60 02 ff 80 00")), "Set lighting color to #FF8000"
|
|
)
|
|
|
|
def test_color_is_a_distinct_mode_and_play_pause_is_an_event(self):
|
|
self.assertEqual(describe_command(bytes.fromhex("50 03 07")), "Set lighting to Color")
|
|
self.assertEqual(describe_reply(bytes.fromhex("51 03 07")), "Lighting: Color")
|
|
self.assertEqual(describe_reply(bytes.fromhex("70 11")), "Button event: Play / pause")
|
|
|
|
def test_capture_maps_to_english_with_optional_hex(self):
|
|
log = ActivityLog()
|
|
raw = "TX BLE 00 bb 01 0c 00 05 40 03 00 05 00 5a"
|
|
log.record("log", raw)
|
|
log.record("log", "RX BLE 00 bb 00 0c 00 00 0c")
|
|
log.record("frame", Frame(0, 12, b""))
|
|
log.record("frame", Frame(1, 0xAD, bytes.fromhex("41 03 05 00")))
|
|
text = log.text()
|
|
self.assertIn("Sending: Set EQ to Rock", text)
|
|
self.assertIn("Speaker acknowledged: Set EQ to Rock", text)
|
|
self.assertIn("Speaker reports: EQ: Rock", text)
|
|
self.assertNotIn("00 bb", text)
|
|
self.assertIn(raw, log.text(raw=True))
|
|
|
|
def test_ack_is_not_reported_as_applied(self):
|
|
log = ActivityLog()
|
|
log.record("log", "TX BLE 00 bb 01 11 00 05 60 02 ff 80 00 f8")
|
|
log.record("frame", Frame(0, 17, b""))
|
|
self.assertIn("acknowledged: Set lighting color", log.text())
|
|
self.assertNotIn("Speaker reports:", log.text())
|
|
|
|
def test_unknown_reply_is_honest_and_does_not_crash(self):
|
|
self.assertIn("Unmapped", describe_reply(b"\xff"))
|
|
self.assertIn("Unmapped", describe_reply(b""))
|
|
|
|
def test_history_is_bounded(self):
|
|
log = ActivityLog(limit=2)
|
|
for value in ("one", "two", "three"):
|
|
log.record("log", value)
|
|
self.assertEqual(log.text(), "two\nthree\n")
|