from visca_xu_bridge import parse_visca, visca_frames def test_visca_split_frames(): frames, rest = visca_frames(bytes([0x81, 0x01, 0x06, 0x04, 0xFF, 0x81])) assert frames == [bytes([0x81, 0x01, 0x06, 0x04, 0xFF])] assert rest == bytes([0x81]) def test_visca_stop_and_move(): stop = parse_visca(bytes([0x81, 0x01, 0x06, 0x01, 0x15, 0x15, 0x03, 0x03, 0xFF])) assert stop["action"] == "stop" left = parse_visca(bytes([0x81, 0x01, 0x06, 0x01, 0x08, 0x08, 0x01, 0x03, 0xFF])) assert left == {"action": "move", "pan": -1.0, "tilt": 0.0, "zoom": 0.0} up = parse_visca(bytes([0x81, 0x01, 0x06, 0x01, 0x08, 0x08, 0x03, 0x01, 0xFF])) assert up["tilt"] == 1.0 def test_visca_zoom_home_preset(): assert parse_visca(bytes([0x81, 0x01, 0x04, 0x07, 0x00, 0xFF]))["action"] == "zoom_stop" tele = parse_visca(bytes([0x81, 0x01, 0x04, 0x07, 0x27, 0xFF])) assert tele == {"action": "zoom", "zoom": 1.0} assert parse_visca(bytes([0x81, 0x01, 0x06, 0x04, 0xFF]))["action"] == "home" rec = parse_visca(bytes([0x81, 0x01, 0x04, 0x3F, 0x02, 0x01, 0xFF])) assert rec == {"action": "preset_recall", "index": 1}