feat(backend): KDS settings as device config, zone enforced for kitchen screens, KDS-only API (platform-v2 3.2a)

- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
  behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
  manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
  and signs waiter messages with its zone/name. New GET /api/kds/context and
  POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
  Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
  person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
  manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
  restart check (one flaky 403).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 18:56:59 +02:00
co-authored by Claude Opus 5.5
parent c24cb72640
commit d5c4400fde
17 changed files with 762 additions and 140 deletions
+25 -6
View File
@@ -187,12 +187,13 @@ def test_config_validated_and_effective(client, pair, owner_h): # "done when" 4
assert err(r) == "validation.device_config"
token, r = pair("kds")
assert r.json()["config"] == {"auto_sign_out_minutes": 0} # defaults filled
defaults = {f.key: f.default for f in device_config.for_app("kds")}
assert r.json()["config"] == defaults # defaults filled
dev_id = r.json()["id"]
r = client.patch(f"/api/devices/{dev_id}", headers=owner_h, json={"config": {"auto_sign_out_minutes": 5}})
assert r.status_code == 200 and r.json()["config"] == {"auto_sign_out_minutes": 5}
assert r.status_code == 200 and r.json()["config"] == {**defaults, "auto_sign_out_minutes": 5}
assert client.get("/api/devices/me", headers={"X-Xenia-Device": token}).json()["config"] \
== {"auto_sign_out_minutes": 5}
== {**defaults, "auto_sign_out_minutes": 5}
assert err(client.patch(f"/api/devices/{dev_id}", headers=owner_h,
json={"config": {"auto_sign_out_minutes": True}})) == "validation.device_config"
# an app without config fields refuses any key
@@ -203,9 +204,13 @@ def test_config_validated_and_effective(client, pair, owner_h): # "done when" 4
def test_module_catalogue_describes_config(client, owner_h):
mods = {m["key"]: m for m in client.get("/api/platform/modules", headers=owner_h).json()["modules"]}
assert mods["kds"]["device_app"]["config"] == [{"key": "auto_sign_out_minutes", "type": "int", "default": 0,
"choices": [0, 2, 5, 10, 30, 60], "min": None, "max": None,
"choices_from": None}]
assert mods["pos_counter"]["device_app"]["config"] == [{"key": "auto_sign_out_minutes", "type": "int", "default": 0,
"choices": [0, 2, 5, 10, 30, 60], "min": None, "max": None,
"choices_from": None, "group": None, "after": None}]
kds = {f["key"]: f for f in mods["kds"]["device_app"]["config"]}
assert kds["prep_zone_id"] == {"key": "prep_zone_id", "type": "ref", "default": None, "choices": [], "min": None,
"max": None, "choices_from": "prep_zones", "group": "zone", "after": None}
assert kds["age_late_minutes"]["after"] == "age_warning_minutes" and kds["colour_fresh"]["type"] == "color"
assert mods["customer_display"]["device_app"]["config"] == []
@@ -234,3 +239,17 @@ def test_config_field_types(db, pair):
eff = device_config.effective(fields, {"zone": 99999, "layout": "tiles", "scale": 120}, db)
assert eff == {"zone": None, "pos": None, "sound": True, "layout": "grid", "scale": 120, "title": ""}
assert device_config.effective(fields, "junk") == {f.key: f.default for f in fields}
def test_config_colours_and_ordered_fields():
fields = (ConfigField("ink", "color", default="#000000"),
ConfigField("warn", "int", default=5, min=1, max=60),
ConfigField("late", "int", default=10, min=1, max=60, after="warn"))
assert device_config.validate(fields, {"ink": "#A0b1C2"}, None) == {"ink": "#a0b1c2"}
for bad in ({"ink": "red"}, {"ink": "#abc"}, {"ink": 5}, {"late": 4}, {"warn": 10}, {"warn": 8, "late": 8}):
with pytest.raises(Exception) as e:
device_config.validate(fields, bad, None)
assert e.value.code == "validation.device_config"
assert device_config.validate(fields, {"warn": 20, "late": 30}, None) == {"warn": 20, "late": 30}
# a stored config that breaks the order reads back as the defaults of the ordered fields
assert device_config.effective(fields, {"ink": "#ffffff", "warn": 30, "late": 20}) == {"ink": "#ffffff", "warn": 5, "late": 10}