feat: browser simulator served by the controller, desktop build, browser bridge
- led-simulator: the rig runs the C++ led-driver as WebAssembly (sim-driver/), one single-threaded worker per bar, no cross-origin isolation needed. Rooms (one JSON per room) with an on-page editor, and a pattern gallery. The Python server, Pyodide boot and ring buffer are removed. - sim-controller sim_rig.c: serves /sim/ from an embedded pack, the page's WebSocket and the rooms/flash API. The desktop build embeds it too. - bridge.c: a "browser" bridge kind that carries ESP-NOW frames to the page; devices announced through it are marked sim. - UI: Simulator in the Menu, split view with resize and pop-out, swipe between controller and rig on phones; SIM/REAL badges in Devices. - Fades: preset pushes and Wi-Fi driver bodies always carry fade and beat_time, so "off" no longer inherits an earlier fade. - Also the sequences-v2 work in progress: desktop port, bridge firmware, serial bridge, Wi-Fi drivers, sequence timeline, audio and API changes. - led-driver: ESP-NOW link, beat sync, control messages, sim hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
698c1463c0
commit
581b751904
506 files changed
+42336
-3599
No files matched your search
@@ -33,7 +33,11 @@ def test_start_stop(c):
|
||||
|
||||
def test_devices(c):
|
||||
data = c.get("/api/audio/devices").json()
|
||||
assert data["devices"][0]["is_default"] is True
|
||||
assert isinstance(data["devices"], list)
|
||||
# The board's only input is the I2S mic, marked as the default. The desktop lists real input sources
|
||||
# (no default marker: the page's "System default input" entry stands for that).
|
||||
if data["devices"] and data["devices"][0]["id"] == "i2s":
|
||||
assert data["devices"][0]["is_default"] is True
|
||||
resp = c.put("/api/audio/device", json={"device_select": "i2s"})
|
||||
assert resp.json()["audio_run"]["device_select"] == "i2s"
|
||||
|
||||
|
||||
@@ -70,3 +70,23 @@ def test_sequence_round_trip(c, profile):
|
||||
step = resp.json()[new]["lanes"][0][0]
|
||||
assert step["beats"] == 3 and step["preset_id"] != a
|
||||
assert step["preset_id"] in c.get("/presets").json()
|
||||
|
||||
|
||||
def test_profile_import_folds_animation_ids(c, profile):
|
||||
"""Older bundles list a zone's one-shots apart, in animation_ids: they land in sequence_ids."""
|
||||
a = next(iter(c.get("/presets").json()))
|
||||
sid = new_id(c.post("/sequences", json={"name": "pytest-seq", "lanes": [[{"preset_id": a, "beats": 2}]]}))
|
||||
oid = new_id(c.post("/sequences", json={"name": "pytest-once", "loop": False,
|
||||
"lanes": [[{"preset_id": a, "beats": 1}]]}))
|
||||
zid = c.get(f"/profiles/{profile}").json()["zones"][0]
|
||||
c.put(f"/zones/{zid}", json={"sequence_ids": [sid, oid]})
|
||||
bundle = c.get(f"/profiles/{profile}/export").json()
|
||||
z = bundle["zones"][zid]
|
||||
z["sequence_ids"], z["animation_ids"] = [sid], [oid] # as an older controller exported it
|
||||
|
||||
new = c.post("/profiles/import", json={"bundle": bundle, "name": "pytest-imported"}).json()["id"]
|
||||
zone = c.get(f"/zones/{c.get(f'/profiles/{new}').json()['zones'][0]}").json()
|
||||
assert "animation_ids" not in zone
|
||||
names = [c.get(f"/sequences/{s}").json()["name"] for s in zone["sequence_ids"]]
|
||||
assert names == ["pytest-seq", "pytest-once"]
|
||||
c.delete(f"/profiles/{new}")
|
||||
+22
-18
@@ -2,8 +2,9 @@ import pytest
|
||||
|
||||
# Test MACs from v1; no real driver has them
|
||||
ESPNOW_MAC = "aabbccddeeff"
|
||||
WIFI_MAC = "102030405060"
|
||||
WIFI_MAC2 = "102030405061"
|
||||
# Wi-Fi drivers are keyed by their mDNS hostname (12 characters or fewer), not a MAC
|
||||
WIFI_ID = "pytest-drv"
|
||||
WIFI_ID2 = "pytest-drv2"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -17,12 +18,12 @@ def espnow_dev(c):
|
||||
|
||||
@pytest.fixture
|
||||
def wifi_dev(c):
|
||||
c.delete(f"/devices/{WIFI_MAC}")
|
||||
c.delete(f"/devices/{WIFI_ID}")
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi", "type": "led", "transport": "wifi",
|
||||
"address": "192.168.50.10", "mac": WIFI_MAC})
|
||||
"address": WIFI_ID})
|
||||
assert resp.status_code == 201, resp.text
|
||||
yield resp
|
||||
c.delete(f"/devices/{WIFI_MAC}")
|
||||
c.delete(f"/devices/{WIFI_ID}")
|
||||
|
||||
|
||||
def test_list(c):
|
||||
@@ -55,28 +56,31 @@ def test_get_espnow_has_no_connection_state(c, espnow_dev):
|
||||
|
||||
|
||||
def test_create_wifi(c, wifi_dev):
|
||||
rec = wifi_dev.json()[WIFI_MAC]
|
||||
rec = wifi_dev.json()[WIFI_ID]
|
||||
assert rec["transport"] == "wifi"
|
||||
assert rec["address"] == "192.168.50.10"
|
||||
assert c.get(f"/devices/{WIFI_MAC}").json().get("connected") is False
|
||||
assert rec["id"] == WIFI_ID
|
||||
assert rec["address"] == f"{WIFI_ID}.local"
|
||||
assert c.get(f"/devices/{WIFI_ID}").json().get("connected") is False
|
||||
|
||||
|
||||
def test_create_second_wifi_same_name(c, wifi_dev):
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi", "transport": "wifi",
|
||||
"address": "192.168.50.11", "mac": WIFI_MAC2})
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi", "transport": "wifi", "address": WIFI_ID2})
|
||||
assert resp.status_code == 201
|
||||
assert resp.json()[WIFI_MAC2]["name"] == "pytest-wifi"
|
||||
assert c.delete(f"/devices/{WIFI_MAC2}").status_code == 200
|
||||
assert resp.json()[WIFI_ID2]["name"] == "pytest-wifi"
|
||||
assert c.delete(f"/devices/{WIFI_ID2}").status_code == 200
|
||||
|
||||
|
||||
def test_create_duplicate_mac(c, wifi_dev):
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi-dupmac", "transport": "wifi",
|
||||
"address": "192.168.50.99", "mac": WIFI_MAC})
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi-dupmac", "transport": "wifi", "address": WIFI_ID})
|
||||
assert resp.status_code == 409
|
||||
|
||||
|
||||
def test_create_wifi_requires_mac(c):
|
||||
resp = c.post("/devices", json={"name": "no-mac-wifi", "transport": "wifi", "address": "192.168.50.12"})
|
||||
def test_create_wifi_requires_hostname(c):
|
||||
assert c.post("/devices", json={"name": "no-host-wifi", "transport": "wifi"}).status_code == 400
|
||||
|
||||
|
||||
def test_create_wifi_rejects_ip_address(c):
|
||||
resp = c.post("/devices", json={"name": "ip-wifi", "transport": "wifi", "address": "192.168.50.12"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@@ -89,8 +93,8 @@ def test_rename_blank(c, espnow_dev):
|
||||
|
||||
|
||||
def test_rename(c, espnow_dev, wifi_dev):
|
||||
for mac in (ESPNOW_MAC, WIFI_MAC):
|
||||
resp = c.put(f"/devices/{mac}", json={"name": "renamed"})
|
||||
for dev in (ESPNOW_MAC, WIFI_ID):
|
||||
resp = c.put(f"/devices/{dev}", json={"name": "renamed"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["name"] == "renamed"
|
||||
|
||||
|
||||
+82
-20
@@ -81,9 +81,9 @@ def test_sync_phase_needs_playback(c):
|
||||
assert c.post("/sequences/sync-phase", json={"mode": "step"}).status_code == 409
|
||||
|
||||
|
||||
def test_plays_on_beats_and_finishes(c, zone, clock):
|
||||
def test_plays_on_beats(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"), "loop": False,
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"),
|
||||
"lanes": [[{"preset_id": a, "beats": 2}, {"preset_id": b, "beats": 1}]]}))
|
||||
resp = c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
assert resp.status_code == 200
|
||||
@@ -94,16 +94,14 @@ def test_plays_on_beats_and_finishes(c, zone, clock):
|
||||
assert st["lane0_current_step"] == 1 and st["lane0_beats_per_step"] == 2
|
||||
assert st["sequence_beats_per_pass"] == 3
|
||||
seen = set()
|
||||
deadline = time.monotonic() + 10 * BEAT_S
|
||||
deadline = time.monotonic() + 4 * BEAT_S
|
||||
while time.monotonic() < deadline:
|
||||
st = c.get("/sequences/status").json()
|
||||
if not st["active"]:
|
||||
break
|
||||
seen.add(st["lane0_current_step"])
|
||||
time.sleep(BEAT_S / 3)
|
||||
assert st["active"] is False, "sequence should end after its 3 beats"
|
||||
assert st["active"] is True, "a looping sequence keeps playing"
|
||||
assert {1, 2} <= seen
|
||||
assert c.get("/api/audio/status").json()["status"]["beat_readout"] == "3/3"
|
||||
# (A loop-off sequence is a one-shot: see test_play_routes_oneshot_over_preset)
|
||||
|
||||
|
||||
def test_loops_and_stops(c, zone, clock):
|
||||
@@ -231,12 +229,14 @@ def test_chase_moves_and_bounces(c, zone, clock):
|
||||
assert seen[:5] == [0, 1, 2, 1, 0][: len(seen[:5])] and len(seen) >= 4
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- animations
|
||||
# ------------------------------------------------------------------- one-shots
|
||||
# A sequence with loop off is a one-shot: it plays once over whatever runs in the zone, then the zone goes
|
||||
# back to its last looping preset or sequence. /fire plays one; /play routes one-shots the same way.
|
||||
|
||||
|
||||
def test_animation_plays_once_alone(c, zone, clock):
|
||||
def test_oneshot_plays_once_alone(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", loop=False, targets=TARGETS[:1], lanes=[[{"preset_id": a, "beats": 2}]],
|
||||
aid = make(c, loop=False, targets=TARGETS[:1], lanes=[[{"preset_id": a, "beats": 2}]],
|
||||
lane_opts=[{"targets": [0]}])
|
||||
resp = c.post(f"/sequences/{aid}/fire", json={"zone_id": zone})
|
||||
assert resp.status_code == 200 and resp.json()["wait"] == "now"
|
||||
@@ -246,35 +246,84 @@ def test_animation_plays_once_alone(c, zone, clock):
|
||||
assert st["overlay"]["active"] is False
|
||||
|
||||
|
||||
def test_animation_over_sequence_keeps_time(c, zone, clock):
|
||||
def test_oneshot_is_timed_in_seconds(c, zone, clock):
|
||||
# Whatever its advance_mode says, a one-shot counts seconds: 1.5 s, not 99 beats (~30 s at 200 BPM)
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, loop=False, advance_mode="beats", targets=TARGETS[:1],
|
||||
lanes=[[{"preset_id": a, "seconds": 1.5, "beats": 99}]], lane_opts=[{"targets": [0]}])
|
||||
assert c.post(f"/sequences/{aid}/fire", json={"zone_id": zone}).status_code == 200
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["lanes"][0]["mode"] == "time", "a one-shot's lanes are timed"
|
||||
t0 = time.monotonic()
|
||||
while time.monotonic() - t0 < 10 and c.get("/sequences/status").json()["overlay"]["active"]:
|
||||
time.sleep(0.1)
|
||||
elapsed = time.monotonic() - t0
|
||||
assert c.get("/sequences/status").json()["overlay"]["active"] is False
|
||||
assert elapsed < 6, "the one-shot ends after its seconds"
|
||||
|
||||
|
||||
def test_play_routes_oneshot_over_preset(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
# A 6-beat pass, so the beat count can't wrap round while the animation plays
|
||||
assert c.post(f"/zones/{zone}/play", json={"preset_id": a}).status_code == 200 # the looping preset
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
assert c.post(f"/sequences/{aid}/play", json={"zone_id": zone}).status_code == 200
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False, "a one-shot never becomes the zone's looping sequence"
|
||||
assert st["overlay"]["active"] is True and st["overlay"]["sequence_id"] == aid
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is False and st["active"] is False
|
||||
|
||||
|
||||
def test_oneshot_over_sequence_keeps_time(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
# A 6-beat pass, so the beat count can't wrap round while the one-shot plays
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 3}, {"preset_id": b, "beats": 3}]],
|
||||
lanes_group_ids=[["pytest-g1"]])
|
||||
aid = make(c, kind="animation", loop=False, lanes=[[{"preset_id": b, "beats": 3}]],
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 3}]],
|
||||
targets=[{"group_ids": ["pytest-g1"]}], lane_opts=[{"targets": [0]}])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
c.post(f"/sequences/{aid}/fire", json={}) # the playing sequence's zone
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["sequence_beat_at"] >= 2, beats=4)
|
||||
assert st["overlay"]["active"] is True and st["active"] is True and st["sequence_id"] == sid
|
||||
assert st["sequence_beat_at"] >= 2, "the sequence keeps counting under the animation"
|
||||
assert st["sequence_beat_at"] >= 2, "the sequence keeps counting under the one-shot"
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is False and st["active"] is True and st["sequence_id"] == sid
|
||||
|
||||
|
||||
def test_animation_step_fires_overlay(c, zone, clock):
|
||||
def test_oneshot_clip_lasts_its_length(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
aid = make(c, kind="animation", loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": aid, "beats": 1, "length": "animation"}]])
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": aid, "beats": 3}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is True and st["overlay"]["sequence_id"] == aid
|
||||
assert st["lanes"][0]["beats_in_step"] == 2, "the step lasts as long as the animation"
|
||||
assert st["lanes"][0]["beats_in_step"] == 3, "the clip lasts as long as it is drawn"
|
||||
|
||||
|
||||
def test_looping_sequence_as_clip_plays_once(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
lid = make(c, lanes=[[{"preset_id": b, "beats": 1}]]) # loops on its own
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": lid, "beats": 6}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is True
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"], beats=4)
|
||||
assert st["overlay"]["active"] is False, "over the zone it plays once, not for ever"
|
||||
|
||||
|
||||
def test_legacy_animation_kind_plays_once(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", lanes=[[{"preset_id": a, "beats": 1}]])
|
||||
rec = c.get(f"/sequences/{aid}").json()
|
||||
assert rec["loop"] is False and "kind" not in rec, "an older client's animation is a one-shot"
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False and st["overlay"]["active"] is True
|
||||
|
||||
|
||||
def test_overlay_stop_and_fire_errors(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", loop=True, lanes=[[{"preset_id": a, "beats": 1}]])
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": a, "beats": 8}]])
|
||||
assert c.post("/sequences/999999/fire", json={"zone_id": zone}).status_code == 404
|
||||
c.post("/sequences/stop")
|
||||
assert c.post(f"/sequences/{aid}/fire", json={}).status_code == 400 # no zone, nothing playing
|
||||
@@ -283,3 +332,16 @@ def test_overlay_stop_and_fire_errors(c, zone, clock):
|
||||
assert st["overlay"]["active"] is True
|
||||
assert c.post("/sequences/overlay/stop").json() == {"ok": True}
|
||||
assert c.get("/sequences/status").json()["overlay"]["active"] is False
|
||||
|
||||
def test_preset_takes_over_from_sequence(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 2}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
assert c.get("/sequences/status").json()["active"] is True
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": a, "beats": 4}]])
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
# The UI has sent the preset to the drivers itself
|
||||
assert c.post(f"/zones/{zone}/play", json={"preset_id": b, "drivers": False}).status_code == 200
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False, "a looping preset replaces the zone's looping sequence"
|
||||
assert st["overlay"]["active"] is True, "the one-shot carries on, then comes back to the preset"
|
||||
Reference in new issue
Block a user