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
+27 -2
View File
@@ -15,12 +15,19 @@ Agent notes:
(`<app>.config.<key>.label`, plus `.choices.<value>` per choice); test_module_texts fails
otherwise. The manager renders the fields generically (DeviceConfigFields.jsx).
- `ref` sources: "prep_zones" (PrepZone ids), "devices:<app_key>" (live devices of that app).
- `color` = "#rrggbb" (lower-cased when stored). `after="<key>"` (int fields): the value must be
greater than that field's (stored or default) value, e.g. KDS age thresholds; a stored
config that breaks the order reads back as the defaults of every ordered field (3.2a).
- `group` only sections the manager's dialogs (modules:<app>.config_groups.<group>).
"""
from __future__ import annotations
import re
from core.errors import XeniaError
MAX_STR = 200
_COLOR = re.compile(r"^#[0-9a-fA-F]{6}$")
def for_app(app_key: str) -> tuple:
@@ -63,6 +70,8 @@ def _clean(f, value, db, *, strict: bool):
return value.strip() if isinstance(value, str) and len(value) <= MAX_STR else bad()
if f.type == "enum":
return value if value in f.choices else bad()
if f.type == "color":
return value.lower() if isinstance(value, str) and _COLOR.match(value) else bad()
if f.type == "ref":
if value is None:
return None
@@ -86,15 +95,31 @@ def validate(fields, config, db) -> dict | None:
if f is None:
raise _bad(key)
out[key] = _clean(f, value, db, strict=True)
merged = {f.key: out.get(f.key, f.default) for f in fields}
for f in fields:
if f.after and not _ordered(f, merged):
raise _bad(f.key)
return out or None
def _ordered(f, values: dict) -> bool:
a, b = values.get(f.key), values.get(f.after)
return not (isinstance(a, int) and isinstance(b, int)) or a > b
def effective(fields, stored, db=None) -> dict:
stored = stored if isinstance(stored, dict) else {}
return {f.key: (_clean(f, stored[f.key], db, strict=False) if f.key in stored else f.default) for f in fields}
out = {f.key: (_clean(f, stored[f.key], db, strict=False) if f.key in stored else f.default) for f in fields}
ordered = [f for f in fields if f.after]
if any(not _ordered(f, out) for f in ordered):
for f in ordered:
out[f.key] = f.default
out[f.after] = next((g.default for g in fields if g.key == f.after), out[f.after])
return out
def describe(fields) -> list[dict]:
"""The fields for the manager (module catalogue)."""
return [{"key": f.key, "type": f.type, "default": f.default, "choices": list(f.choices),
"min": f.min, "max": f.max, "choices_from": f.choices_from} for f in fields]
"min": f.min, "max": f.max, "choices_from": f.choices_from, "group": f.group, "after": f.after}
for f in fields]
+5 -2
View File
@@ -54,7 +54,7 @@ class SettingDef:
choices: tuple[str, ...] = () # for type "enum"
ConfigType = Literal["bool", "int", "str", "enum", "ref"]
ConfigType = Literal["bool", "int", "str", "enum", "ref", "color"]
@dataclass(frozen=True)
@@ -62,7 +62,8 @@ class ConfigField:
"""One setting of a device running an app (plan step 3.1a). Stored in devices.config,
validated by core/modules/device_config.py, edited in the manager's pair/edit dialogs.
Texts: modules:<app>.config.<key>.label (+ .hint optional, + .choices.<value> for each
choice), checked by tests/test_module_texts.py."""
choice, + .none for a ref's empty choice; groups: modules:<app>.config_groups.<group>),
checked by tests/test_module_texts.py."""
key: str
type: ConfigType
default: object = None
@@ -70,6 +71,8 @@ class ConfigField:
min: Optional[int] = None # int
max: Optional[int] = None # int
choices_from: Optional[str] = None # ref: "prep_zones" | "devices:<app_key>"; value = id or None
group: Optional[str] = None # section in the manager's dialogs (3.2a)
after: Optional[str] = None # int: must be greater than this other field (age thresholds)
@dataclass(frozen=True)