feat: port the remaining v1 API to the v2 controller
Profiles seed presets, a default zone and a palette, and clone with their own copies; deleting a profile removes what it owned. Zones get the v1 list shape, set-current, current, clone and content-fragment. Devices are keyed by MAC with v1 validation and identify. Patterns: definitions, OTA file and manifest, upload, driver, and send over ESP-NOW (the led-driver pattern sources are embedded in the firmware). Pixel outputs get v1 validation and a DDP/Art-Net/sACN test pattern. Sequences, palettes and settings follow v1 replies and validation, and /ws forwards browser messages to the drivers. The resource handlers move out of api.c into res_*.c, patterns.c and outputs.c. cJSON now allocates from PSRAM: the store had grown enough to starve internal RAM and abort the mic at boot. /status reports free_internal. The Wi-Fi AP and led-tool routes are left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b42391a46
commit
57182188ba
30 files changed
+2846
-425
No files matched your search
@@ -1,6 +1,6 @@
|
||||
"""Groups, sequences, scenes and palettes."""
|
||||
|
||||
from helpers import find_id_by_field, missing, new_id, unique
|
||||
from helpers import find_id_by_field, new_id, unique
|
||||
|
||||
|
||||
def test_groups(c):
|
||||
@@ -31,14 +31,12 @@ def test_sequences_crud(c):
|
||||
assert c.delete(f"/sequences/{sid}").status_code == 200
|
||||
|
||||
|
||||
@missing("sequence step validation")
|
||||
def test_sequence_step_needs_preset(c):
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"), "steps": []}))
|
||||
assert c.put(f"/sequences/{sid}", json={"steps": [{"duration_s": 1}]}).status_code == 400
|
||||
c.delete(f"/sequences/{sid}")
|
||||
|
||||
|
||||
@missing("400 for a sequence without zone_id")
|
||||
def test_sequence_without_zone_cannot_play(c):
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"),
|
||||
"steps": [{"preset_id": "1", "duration_s": 1}]}))
|
||||
@@ -46,7 +44,6 @@ def test_sequence_without_zone_cannot_play(c):
|
||||
c.delete(f"/sequences/{sid}")
|
||||
|
||||
|
||||
@missing("sequence play/stop status replies and active flag")
|
||||
def test_sequence_play_and_stop(c):
|
||||
profile = new_id(c.post("/profiles", json={"name": unique("pytest-engine")}))
|
||||
c.post(f"/profiles/{profile}/apply")
|
||||
@@ -80,7 +77,6 @@ def test_scenes(c):
|
||||
assert c.delete(f"/scenes/{sid}").status_code == 200
|
||||
|
||||
|
||||
@missing("v1 palette shape ({id, colors})")
|
||||
def test_palettes(c):
|
||||
resp = c.post("/palettes", json={"colors": ["#112233", "#445566"]})
|
||||
assert resp.status_code == 201
|
||||
@@ -95,7 +91,6 @@ def test_palettes(c):
|
||||
assert c.delete(f"/palettes/{pid}").status_code == 200
|
||||
|
||||
|
||||
@missing("v1 palette shape ({id, colors})")
|
||||
def test_palettes_list_is_colour_lists(c):
|
||||
pid = str(c.post("/palettes", json={"colors": ["#abcdef"]}).json()["id"])
|
||||
assert c.get("/palettes").json()[pid] == ["#abcdef"]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing
|
||||
|
||||
# Test MACs from v1; no real driver has them
|
||||
ESPNOW_MAC = "aabbccddeeff"
|
||||
WIFI_MAC = "102030405060"
|
||||
@@ -33,12 +31,10 @@ def test_list(c):
|
||||
assert isinstance(resp.json(), dict)
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_requires_name(c):
|
||||
assert c.post("/devices", json={}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_espnow_keyed_by_mac(espnow_dev):
|
||||
dev = espnow_dev.json()
|
||||
assert list(dev) == [ESPNOW_MAC]
|
||||
@@ -50,7 +46,6 @@ def test_create_espnow_keyed_by_mac(espnow_dev):
|
||||
assert rec["address"] == ESPNOW_MAC
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_get_espnow_has_no_connection_state(c, espnow_dev):
|
||||
resp = c.get(f"/devices/{ESPNOW_MAC}")
|
||||
assert resp.status_code == 200
|
||||
@@ -59,7 +54,6 @@ def test_get_espnow_has_no_connection_state(c, espnow_dev):
|
||||
assert c.get("/devices").json()[ESPNOW_MAC].get("connected") is None
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_wifi(c, wifi_dev):
|
||||
rec = wifi_dev.json()[WIFI_MAC]
|
||||
assert rec["transport"] == "wifi"
|
||||
@@ -67,7 +61,6 @@ def test_create_wifi(c, wifi_dev):
|
||||
assert c.get(f"/devices/{WIFI_MAC}").json().get("connected") is False
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
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})
|
||||
@@ -76,30 +69,25 @@ def test_create_second_wifi_same_name(c, wifi_dev):
|
||||
assert c.delete(f"/devices/{WIFI_MAC2}").status_code == 200
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
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})
|
||||
assert resp.status_code == 409
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_wifi_requires_mac(c):
|
||||
resp = c.post("/devices", json={"name": "no-mac-wifi", "transport": "wifi", "address": "192.168.50.12"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_rejects_unknown_transport(c):
|
||||
assert c.post("/devices", json={"name": "bad-tr", "transport": "serial"}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_rename_blank(c, espnow_dev):
|
||||
assert c.put(f"/devices/{ESPNOW_MAC}", json={"name": " "}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_rename(c, espnow_dev, wifi_dev):
|
||||
for mac in (ESPNOW_MAC, WIFI_MAC):
|
||||
resp = c.put(f"/devices/{mac}", json={"name": "renamed"})
|
||||
@@ -107,19 +95,16 @@ def test_rename(c, espnow_dev, wifi_dev):
|
||||
assert resp.json()["name"] == "renamed"
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_cannot_change_mac(c, espnow_dev):
|
||||
assert c.put(f"/devices/{ESPNOW_MAC}", json={"mac": "001122334455"}).status_code == 400
|
||||
|
||||
|
||||
@missing("device identify")
|
||||
def test_identify(c, espnow_dev):
|
||||
resp = c.post(f"/devices/{ESPNOW_MAC}/identify")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json().get("message")
|
||||
|
||||
|
||||
@missing("device identify")
|
||||
def test_identify_unknown(c):
|
||||
assert c.post("/devices/000000000000/identify").status_code == 404
|
||||
|
||||
@@ -130,7 +115,6 @@ def test_status(c):
|
||||
assert isinstance(resp.json(), dict)
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_delete(c, espnow_dev):
|
||||
assert c.delete(f"/devices/{ESPNOW_MAC}").status_code == 200
|
||||
assert c.get(f"/devices/{ESPNOW_MAC}").status_code == 404
|
||||
@@ -1,20 +0,0 @@
|
||||
"""led-tool: configure drivers over USB serial (v1 controllers/led_tool.py)."""
|
||||
|
||||
from helpers import missing
|
||||
|
||||
# Every test here fails on v2
|
||||
pytestmark = missing("led-tool (USB serial)")
|
||||
|
||||
|
||||
def test_ports(c):
|
||||
resp = c.get("/led-tool/ports")
|
||||
assert resp.status_code == 200
|
||||
assert isinstance(resp.json()["ports"], list)
|
||||
|
||||
|
||||
def test_settings_requires_port(c):
|
||||
assert c.get("/led-tool/settings").status_code == 400
|
||||
|
||||
|
||||
def test_reset_requires_port(c):
|
||||
assert c.post("/led-tool/reset", json={}).status_code == 400
|
||||
@@ -1,10 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing
|
||||
|
||||
# Every test here fails on v2
|
||||
pytestmark = missing("pixel outputs (DDP, Art-Net, sACN, DMX)")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def output(c):
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
from helpers import missing, unique
|
||||
from helpers import unique
|
||||
|
||||
|
||||
@missing("/patterns/definitions")
|
||||
def test_definitions(c):
|
||||
resp = c.get("/patterns/definitions")
|
||||
assert resp.status_code == 200
|
||||
assert isinstance(resp.json(), dict)
|
||||
|
||||
|
||||
@missing("driver pattern files in /patterns")
|
||||
def test_list_includes_driver_patterns(c):
|
||||
resp = c.get("/patterns")
|
||||
assert resp.status_code == 200
|
||||
assert "blink" in resp.json()
|
||||
|
||||
|
||||
@missing("v1 pattern create ({name, data})")
|
||||
def test_crud(c):
|
||||
pid = unique("pytest_pattern").replace("-", "_")
|
||||
resp = c.post("/patterns", json={"name": pid, "data": {"foo": "bar"}})
|
||||
@@ -30,7 +27,6 @@ def test_crud(c):
|
||||
assert c.delete(f"/patterns/{pid}").status_code == 200
|
||||
|
||||
|
||||
@missing("/patterns/ota/file")
|
||||
def test_ota_file(c):
|
||||
resp = c.get("/patterns/ota/file/blink.py")
|
||||
assert resp.status_code == 200
|
||||
@@ -38,7 +34,6 @@ def test_ota_file(c):
|
||||
assert "class" in resp.text
|
||||
|
||||
|
||||
@missing("/patterns/ota/file")
|
||||
def test_ota_file_rejects_builtin(c):
|
||||
# on/off are built into the driver firmware, not OTA files
|
||||
resp = c.get("/patterns/ota/file/on.py")
|
||||
@@ -46,7 +41,6 @@ def test_ota_file_rejects_builtin(c):
|
||||
assert "error" in resp.json()
|
||||
|
||||
|
||||
@missing("/patterns/ota/manifest")
|
||||
def test_ota_manifest(c):
|
||||
resp = c.get("/patterns/ota/manifest")
|
||||
assert resp.status_code == 200
|
||||
@@ -54,20 +48,17 @@ def test_ota_manifest(c):
|
||||
assert "blink.py" in names
|
||||
|
||||
|
||||
@missing("/patterns/<name>/send")
|
||||
def test_send_rejects_builtin(c):
|
||||
resp = c.post("/patterns/off/send", json={})
|
||||
assert resp.status_code == 400
|
||||
assert "error" in resp.json()
|
||||
|
||||
|
||||
@missing("/patterns/upload")
|
||||
def test_upload_rejects_builtin(c):
|
||||
resp = c.post("/patterns/upload", json={"name": "on.py", "code": "class On:\n def run(self, p):\n yield\n"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@missing("/patterns/driver")
|
||||
def test_driver_rejects_builtin(c):
|
||||
resp = c.post("/patterns/driver", json={"name": "off", "code": "class Off:\n def run(self, p):\n yield\n"})
|
||||
assert resp.status_code == 400
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing, new_id, unique
|
||||
from helpers import new_id, unique
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -21,7 +21,6 @@ def preset(c, profile):
|
||||
c.delete(f"/presets/{pid}")
|
||||
|
||||
|
||||
@missing("seeded presets for a new profile")
|
||||
def test_list_and_get(c, profile):
|
||||
resp = c.get("/presets")
|
||||
assert resp.status_code == 200
|
||||
@@ -40,7 +39,6 @@ def test_create_belongs_to_current_profile(c, profile):
|
||||
assert str(resp.json()[pid]["profile_id"]) == profile
|
||||
|
||||
|
||||
@missing("preset defaults on create")
|
||||
def test_create_fills_defaults(c, profile):
|
||||
resp = c.post("/presets", json={"name": unique("pytest-preset"), "pattern": "on"})
|
||||
rec = resp.json()[new_id(resp)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing, new_id, unique
|
||||
from helpers import new_id, unique
|
||||
|
||||
# Presets every new profile is seeded with (v1 controllers/profile.py)
|
||||
SEEDED = {"on", "off", "rainbow", "Colour Cycle", "transition", "flicker", "flame", "twinkle"}
|
||||
@@ -35,7 +35,6 @@ def test_apply_unknown_profile(c):
|
||||
assert c.post("/profiles/999999/apply").status_code == 404
|
||||
|
||||
|
||||
@missing("profile seeding (presets, default zone, palette)")
|
||||
def test_new_profile_is_seeded(c, profile):
|
||||
presets = c.get("/presets").json()
|
||||
assert SEEDED <= {p["name"] for p in presets.values()}
|
||||
@@ -61,7 +60,6 @@ def test_put(c, profile):
|
||||
assert resp.json()["name"] == name
|
||||
|
||||
|
||||
@missing("profile clone")
|
||||
def test_clone(c, profile):
|
||||
name = unique("pytest-profile-clone")
|
||||
resp = c.post(f"/profiles/{profile}/clone", json={"name": name})
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing
|
||||
|
||||
|
||||
def test_index(c):
|
||||
resp = c.get("/")
|
||||
@@ -24,7 +22,6 @@ def test_settings_page(c):
|
||||
assert "LED Controller" in resp.text
|
||||
|
||||
|
||||
@missing("/ws")
|
||||
def test_ws_rejects_plain_get(c):
|
||||
# A websocket endpoint refuses a request that is not an upgrade
|
||||
resp = c.get("/ws")
|
||||
|
||||
@@ -1,49 +1,15 @@
|
||||
from helpers import missing, unique
|
||||
|
||||
|
||||
@missing("settings defaults")
|
||||
def test_get_settings(c):
|
||||
resp = c.get("/settings")
|
||||
assert resp.status_code == 200
|
||||
assert "wifi_channel" in resp.json()
|
||||
|
||||
|
||||
@missing("/settings/wifi/ap")
|
||||
def test_wifi_ap_get(c):
|
||||
resp = c.get("/settings/wifi/ap")
|
||||
assert resp.status_code == 200
|
||||
ap = resp.json()
|
||||
assert "saved_ssid" in ap
|
||||
assert "active" in ap
|
||||
|
||||
|
||||
@missing("/settings/wifi/ap")
|
||||
def test_wifi_ap_post(c):
|
||||
ssid = unique("pytest-ssid")
|
||||
resp = c.post("/settings/wifi/ap", json={"ssid": ssid, "password": "secret", "channel": 1})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["ssid"] == ssid
|
||||
assert resp.json()["channel"] == 1
|
||||
assert c.get("/settings/wifi/ap").json()["saved_ssid"] == ssid
|
||||
|
||||
|
||||
@missing("/settings/wifi/ap")
|
||||
def test_wifi_ap_rejects_bad_channel(c):
|
||||
resp = c.post("/settings/wifi/ap", json={"ssid": "bad-ssid", "password": "secret", "channel": 12})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@missing("/settings/wifi/ap")
|
||||
def test_wifi_ap_requires_ssid(c):
|
||||
assert c.post("/settings/wifi/ap", json={"password": "secret"}).status_code == 400
|
||||
|
||||
|
||||
def test_wifi_channel(c):
|
||||
assert c.put("/settings/settings", json={"wifi_channel": 11}).status_code == 200
|
||||
assert c.get("/settings").json()["wifi_channel"] == 11
|
||||
|
||||
|
||||
@missing("settings validation")
|
||||
def test_wifi_channel_out_of_range(c):
|
||||
assert c.put("/settings/settings", json={"wifi_channel": 12}).status_code == 400
|
||||
|
||||
@@ -53,6 +19,5 @@ def test_global_brightness(c):
|
||||
assert c.get("/settings").json().get("global_brightness") == 42
|
||||
|
||||
|
||||
@missing("settings validation")
|
||||
def test_global_brightness_out_of_range(c):
|
||||
assert c.put("/settings/settings", json={"global_brightness": 300}).status_code == 400
|
||||
+1
-11
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing, new_id, unique
|
||||
from helpers import new_id, unique
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -21,7 +21,6 @@ def zone(c, profile):
|
||||
c.delete(f"/zones/{zid}")
|
||||
|
||||
|
||||
@missing("v1 zone list shape and profile zone order")
|
||||
def test_list(c, profile, zone):
|
||||
resp = c.get("/zones")
|
||||
assert resp.status_code == 200
|
||||
@@ -32,12 +31,10 @@ def test_list(c, profile, zone):
|
||||
assert "current_zone_id" in data
|
||||
|
||||
|
||||
@missing("adding new zones to the current profile")
|
||||
def test_create_adds_to_profile(c, profile, zone):
|
||||
assert zone in c.get(f"/profiles/{profile}").json()["zones"]
|
||||
|
||||
|
||||
@missing("zone validation")
|
||||
def test_create_requires_name(c, profile):
|
||||
assert c.post("/zones", json={"names": ["1"]}).status_code == 400
|
||||
|
||||
@@ -48,7 +45,6 @@ def test_get(c, zone):
|
||||
assert resp.json()["name"].startswith("pytest-zone")
|
||||
|
||||
|
||||
@missing("zone set-current")
|
||||
def test_set_current(c, zone):
|
||||
resp = c.post(f"/zones/{zone}/set-current")
|
||||
assert resp.status_code == 200
|
||||
@@ -59,7 +55,6 @@ def test_set_current(c, zone):
|
||||
assert resp.json()["zone_id"] == zone
|
||||
|
||||
|
||||
@missing("zone set-current")
|
||||
def test_set_current_unknown(c):
|
||||
assert c.post("/zones/999999/set-current").status_code == 404
|
||||
|
||||
@@ -75,7 +70,6 @@ def test_edit_workflow(c, zone):
|
||||
assert stored["names"] == ["2", "3", "4"]
|
||||
|
||||
|
||||
@missing("zone clone")
|
||||
def test_clone(c, profile, zone):
|
||||
resp = c.post(f"/zones/{zone}/clone", json={"name": "pytest-zone-clone"})
|
||||
assert resp.status_code == 201
|
||||
@@ -88,7 +82,6 @@ def test_clone(c, profile, zone):
|
||||
assert c.delete(f"/zones/{clone}").status_code == 200
|
||||
|
||||
|
||||
@missing("zone clone")
|
||||
def test_clone_default_name(c, zone):
|
||||
resp = c.post(f"/zones/{zone}/clone", json={})
|
||||
clone = new_id(resp)
|
||||
@@ -96,14 +89,12 @@ def test_clone_default_name(c, zone):
|
||||
c.delete(f"/zones/{clone}")
|
||||
|
||||
|
||||
@missing("zone content-fragment")
|
||||
def test_content_fragment(c, zone):
|
||||
resp = c.get(f"/zones/{zone}/content-fragment", headers={"HX-Request": "true", "Accept": "text/html"})
|
||||
assert resp.status_code == 200
|
||||
assert f'data-zone-id="{zone}"' in resp.text
|
||||
|
||||
|
||||
@missing("removing deleted zones from the profile")
|
||||
def test_delete_removes_from_profile(c, profile):
|
||||
zid = new_id(c.post("/zones", json={"name": unique("pytest-zone"), "names": ["1"]}))
|
||||
assert c.delete(f"/zones/{zid}").status_code == 200
|
||||
@@ -119,7 +110,6 @@ def test_play_unknown_preset(c, zone):
|
||||
assert c.post(f"/zones/{zone}/play", json={"preset_id": "nope"}).status_code == 404
|
||||
|
||||
|
||||
@missing("zone stop reply ({stopped})")
|
||||
def test_play_and_stop(c, zone):
|
||||
preset = new_id(c.post("/presets", json={"name": "pytest-on", "pattern": "on", "colors": ["#ff0000"]}))
|
||||
resp = c.post(f"/zones/{zone}/play", json={"preset_id": preset})
|
||||
|
||||
Reference in new issue
Block a user