Bragi protocol over hidraw, device service with heartbeat and notifications, PySide6 UI with animated preview, profiles, tray, autostart, udev rule and installer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import unittest
|
|
|
|
from k65studio import bragi, effects
|
|
from k65studio.layout import KEYS, WIDTH
|
|
from k65studio.profiles import Config, Profile
|
|
|
|
|
|
class PacketTests(unittest.TestCase):
|
|
def test_static_color_matches_known_good_capture(self):
|
|
pkts = effects.encode(bragi.TARGET_PAIRED, "static", ["#ff0080"], False, "medium")
|
|
self.assertEqual(len(pkts), 2)
|
|
self.assertEqual(pkts[0][:15].hex(" "), "09 06 01 5d 00 00 00 7e 20 01 00 00 00 01 ff")
|
|
self.assertEqual(pkts[0][15:18], bytes([0x80, 0x00, 0xFF])) # B, G, R
|
|
self.assertEqual(pkts[1][:3], bytes([0x09, 0x07, 0x01]))
|
|
|
|
def test_rainbow_wave_header(self):
|
|
pkt = effects.encode(bragi.TARGET_PAIRED, "rainbow_wave", [], False, "fast")[0]
|
|
self.assertEqual(pkt[3:12].hex(" "), "59 00 00 00 4c b9 00 05 04")
|
|
|
|
def test_random_colors_have_no_color_list(self):
|
|
pkt = effects.encode(bragi.TARGET_PAIRED, "color_shift", ["#ffffff"], True, "slow")[0]
|
|
self.assertEqual(pkt[7:13].hex(" "), "fa a5 02 03 00 00")
|
|
self.assertEqual(pkt[13], 0)
|
|
|
|
def test_two_specific_colors(self):
|
|
pkt = effects.encode(bragi.TARGET_PAIRED, "color_pulse", ["#010203", "#040506"], False, "medium")[0]
|
|
self.assertEqual(pkt[9], bragi.COLORS_SPECIFIC)
|
|
self.assertEqual(pkt[13], 2)
|
|
self.assertEqual(pkt[14:22], bytes([0xFF, 3, 2, 1, 0xFF, 6, 5, 4]))
|
|
|
|
def test_packets_fit_report(self):
|
|
for key in effects.EFFECTS:
|
|
for p in effects.encode(bragi.TARGET_PAIRED, key, ["#123456", "#654321"], False, "medium"):
|
|
self.assertLessEqual(len(p), 64)
|
|
|
|
def test_keymap_block(self):
|
|
pkts = bragi.block_packets(bragi.TARGET_PAIRED, bragi.default_keymap())
|
|
self.assertEqual(len(pkts), 3)
|
|
self.assertEqual(pkts[0][3:5], bytes([123, 0]))
|
|
|
|
|
|
class LayoutTests(unittest.TestCase):
|
|
def test_rows_fit_board(self):
|
|
for k in KEYS:
|
|
self.assertLessEqual(k.x + k.w, WIDTH + 1e-9, k)
|
|
|
|
|
|
class ProfileTests(unittest.TestCase):
|
|
def test_unknown_fields_are_ignored(self):
|
|
p = Profile.from_dict({"effect": "rain", "bogus": 1})
|
|
self.assertEqual(p.effect, "rain")
|
|
|
|
def test_active_falls_back_to_existing_profile(self):
|
|
c = Config(active="weg", profiles={"A": Profile()})
|
|
self.assertIs(c.profile, c.profiles["A"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|