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>
124 lines
4.2 KiB
Python
124 lines
4.2 KiB
Python
"""Device groups (main's controllers/group.py) and combined brightness."""
|
|
|
|
import pytest
|
|
|
|
from helpers import find_id_by_field, new_id, unique
|
|
|
|
MAC = "aabbccddee01" # made up: no driver answers it
|
|
|
|
|
|
@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}")
|
|
|
|
|
|
@pytest.fixture
|
|
def device(c):
|
|
c.delete(f"/devices/{MAC}")
|
|
assert c.post("/devices", json={"name": "pytest-g", "mac": MAC, "output_brightness": 128}).status_code == 201
|
|
yield MAC
|
|
c.delete(f"/devices/{MAC}")
|
|
|
|
|
|
@pytest.fixture
|
|
def group(c, device):
|
|
resp = c.post("/groups", json={"name": unique("pytest-group"), "devices": ["AA:BB:CC:DD:EE:01"],
|
|
"output_brightness": 128})
|
|
assert resp.status_code == 201
|
|
gid = str(resp.json()["id"])
|
|
yield gid
|
|
c.delete(f"/groups/{gid}")
|
|
|
|
|
|
def test_crud(c):
|
|
name = unique("pytest-group")
|
|
resp = c.post("/groups", json={"name": name})
|
|
assert resp.status_code == 201
|
|
assert resp.json()["devices"] == []
|
|
assert resp.json()["output_brightness"] == 255
|
|
gid = find_id_by_field(c.get("/groups").json(), "name", name)
|
|
resp = c.get(f"/groups/{gid}")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"] == name
|
|
resp = c.put(f"/groups/{gid}", json={"brightness": 10})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["brightness"] == 10
|
|
assert c.delete(f"/groups/{gid}").status_code == 200
|
|
assert c.get(f"/groups/{gid}").status_code == 404
|
|
|
|
|
|
def test_device_macs_normalized(c, group):
|
|
assert c.get(f"/groups/{group}").json()["devices"] == [MAC]
|
|
|
|
|
|
def test_profile_scoped_group(c, profile):
|
|
resp = c.post("/groups", json={"name": unique("pytest-scoped"), "profile_scoped": True})
|
|
gid = str(resp.json()["id"])
|
|
assert resp.json()["profile_id"] == profile
|
|
other = new_id(c.post("/profiles", json={"name": unique("pytest-other")}))
|
|
c.post(f"/profiles/{other}/apply")
|
|
assert gid not in c.get("/groups").json()
|
|
assert c.get(f"/groups/{gid}").status_code == 404
|
|
c.post(f"/profiles/{profile}/apply")
|
|
assert gid in c.get("/groups").json()
|
|
c.delete(f"/groups/{gid}")
|
|
c.delete(f"/profiles/{other}")
|
|
|
|
|
|
def test_resolve_brightness(c, group):
|
|
# global 255 x group 128 x device 128 (x zone 255) -> round(255 * 128/255 * 128/255) = 64
|
|
resp = c.post("/devices/resolve-brightness", json={"macs": [MAC], "zone_brightness": 255})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["values"] == {MAC: 64}
|
|
|
|
|
|
def test_resolve_brightness_needs_list(c):
|
|
assert c.post("/devices/resolve-brightness", json={"macs": "x"}).status_code == 400
|
|
|
|
|
|
def test_group_brightness(c, group):
|
|
resp = c.post(f"/groups/{group}/brightness")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["sent"] == 1
|
|
|
|
|
|
def test_group_identify(c, group):
|
|
resp = c.post(f"/groups/{group}/identify")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["sent"] == 1
|
|
|
|
|
|
def test_group_identify_needs_devices(c):
|
|
gid = str(c.post("/groups", json={"name": unique("pytest-empty")}).json()["id"])
|
|
assert c.post(f"/groups/{gid}/identify").status_code == 400
|
|
c.delete(f"/groups/{gid}")
|
|
|
|
|
|
def test_group_driver_config(c, group):
|
|
assert c.post(f"/groups/{group}/driver-config", json={}).status_code == 400
|
|
resp = c.post(f"/groups/{group}/driver-config", json={"wifi_driver_num_leds": 60})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["sent"] == 1
|
|
|
|
|
|
def test_device_brightness_and_config(c, device):
|
|
resp = c.post(f"/devices/{device}/brightness", json={"zone_brightness": 255})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["brightness"] == 128
|
|
assert c.post(f"/devices/{device}/driver-config", json={}).status_code == 400
|
|
assert c.post(f"/devices/{device}/driver-config", json={"num_leds": 30}).status_code == 200
|
|
|
|
|
|
def test_update_groups_push(c):
|
|
resp = c.post("/devices/groups")
|
|
espnow = [d for d in c.get("/devices").json().values() if d.get("transport") == "espnow"]
|
|
if not espnow:
|
|
assert resp.status_code == 400
|
|
return
|
|
data = resp.json()
|
|
assert data["total"] == len(espnow)
|
|
assert data["sent"] + data["failed"] == data["total"]
|