feat: main's import/export, zones, audio API and web UI
Profiles, presets and sequences export and import as main's bundles. Zones carry group_ids, preset_group_ids, sequence_ids, content_kind and brightness; profiles seed rainbow as colour_cycle, and deleting a profile also deletes its sequences. Groups, zones and sequences written by older versions are migrated at boot. /api/audio (status, event stream, start/stop, reset, anchor-bar, devices) maps main's audio detector onto the mic's beat detector. Audio start/stop picks whether mic beats or the BPM clock time sequences; the clock's beats also go to the drivers while the mic is off. /ws now greets from a post-handshake callback (httpd does not call the handler for the upgrade). The web UI is main's, plus v2's outputs editor, list search and hostname/static IP settings; the bridge, Wi-Fi AP and led-tool parts are gone. API tests follow main's behaviour (119 pass on the board). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
04b56c6ef2
commit
bfeeb958df
44 files changed
+8709
-2338
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"""Import/export bundles (main's tests/test_profile_bundle.py over HTTP)."""
|
||||
|
||||
import pytest
|
||||
|
||||
from helpers import new_id, unique
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def profile(c):
|
||||
pid = new_id(c.post("/profiles", json={"name": unique("pytest-profile")}))
|
||||
assert c.post(f"/profiles/{pid}/apply").status_code == 200
|
||||
yield pid
|
||||
c.delete(f"/profiles/{pid}")
|
||||
|
||||
|
||||
def test_profile_round_trip(c, profile):
|
||||
presets = c.get("/presets").json()
|
||||
a = next(iter(presets))
|
||||
sid = new_id(c.post("/sequences", json={"name": "pytest-seq", "lanes": [[{"preset_id": a, "beats": 2}]]}))
|
||||
zid = c.get(f"/profiles/{profile}").json()["zones"][0]
|
||||
c.put(f"/zones/{zid}", json={"sequence_ids": [sid]})
|
||||
c.put(f"/palettes/{c.get(f'/profiles/{profile}').json()['palette_id']}", json={"colors": ["#123456"]})
|
||||
|
||||
bundle = c.get(f"/profiles/{profile}/export").json()
|
||||
assert bundle["version"] == 1 and bundle["kind"] == "profile"
|
||||
assert bundle["palette"]["colors"] == ["#123456"]
|
||||
assert zid in bundle["zones"] and sid in bundle["sequences"]
|
||||
assert set(presets) == set(bundle["presets"])
|
||||
|
||||
resp = c.post("/profiles/import", json={"bundle": bundle, "name": "pytest-imported"})
|
||||
assert resp.status_code == 201
|
||||
new = resp.json()["id"]
|
||||
assert resp.json()[new]["name"] == "pytest-imported"
|
||||
assert c.get("/profiles/current").json()["id"] == new # applied by default
|
||||
imported = c.get("/presets").json()
|
||||
assert len(imported) == len(presets) and not set(imported) & set(presets)
|
||||
nz = c.get(f"/profiles/{new}").json()["zones"]
|
||||
assert len(nz) == 1 and nz[0] != zid
|
||||
zone = c.get(f"/zones/{nz[0]}").json()
|
||||
new_sid = zone["sequence_ids"][0]
|
||||
assert new_sid != sid
|
||||
seq = c.get(f"/sequences/{new_sid}").json()
|
||||
assert seq["lanes"][0][0]["preset_id"] in imported
|
||||
pal = c.get(f"/palettes/{c.get(f'/profiles/{new}').json()['palette_id']}").json()
|
||||
assert pal["colors"] == ["#123456"]
|
||||
c.delete(f"/profiles/{new}")
|
||||
|
||||
|
||||
def test_profile_import_rejects_other_bundles(c, profile):
|
||||
assert c.post("/profiles/import", json={"version": 2, "kind": "profile", "profile": {}}).status_code == 400
|
||||
assert c.post("/profiles/import", json={"version": 1, "kind": "preset", "profile": {}}).status_code == 400
|
||||
assert c.post("/profiles/import", json={"version": 1, "kind": "profile"}).status_code == 400
|
||||
|
||||
|
||||
def test_export_unknown_profile(c):
|
||||
assert c.get("/profiles/999999/export").status_code == 404
|
||||
|
||||
|
||||
def test_preset_round_trip(c, profile):
|
||||
a = next(iter(c.get("/presets").json()))
|
||||
bundle = c.get(f"/presets/{a}/export").json()
|
||||
assert bundle["kind"] == "preset"
|
||||
resp = c.post("/presets/import", json={"bundle": bundle})
|
||||
assert resp.status_code == 201
|
||||
new = new_id(resp)
|
||||
assert new != a
|
||||
assert resp.json()[new]["name"] == bundle["preset"]["name"]
|
||||
assert resp.json()[new]["profile_id"] == profile
|
||||
assert c.post("/presets/import", json={"kind": "sequence"}).status_code == 400
|
||||
|
||||
|
||||
def test_sequence_round_trip(c, profile):
|
||||
a = next(iter(c.get("/presets").json()))
|
||||
sid = new_id(c.post("/sequences", json={"name": "pytest-seq", "lanes": [[{"preset_id": a, "beats": 3}]]}))
|
||||
bundle = c.get(f"/sequences/{sid}/export").json()
|
||||
assert bundle["kind"] == "sequence" and a in bundle["presets"]
|
||||
resp = c.post("/sequences/import", json={"bundle": bundle})
|
||||
assert resp.status_code == 201
|
||||
new = new_id(resp)
|
||||
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()
|
||||
Reference in new issue
Block a user