Panels become devices: per-device documents in the flow repo, a Devices tab

- flow/devices.py: DeviceDef in FLOWS_DIR/_devices/<id>.json, committed under
  the flow store's write lock, 409 on a stale version; nonces in DEVICES_FILE
  outside git; in-memory presence announced as device_status
- api/routes/devices.py: CRUD, pairing with an optional {name, board,
  firmware}, a pending list adopted without a code from the LAN only, unpair;
  /panels/pair, /panels/pair/{code} and GET /panels/{id} kept as aliases,
  PUT /panels/ gone
- _device_may replaces _panel_may, JWT claims unchanged
- panels.json moves into devices once at startup, then .migrated
- MCP list_devices, get_device; search category device
- Devices tab (list, detail with presence, pairing, ordered dashboards,
  touch, I/O), PanelsDialog removed, serialised optimistic saves
This commit is contained in:
Melvin Strobl
2026-10-16 15:48:36 +02:00
parent 3c0912a3fe
commit 28a565e501
56 changed files with 3539 additions and 2404 deletions
+10 -1
View File
@@ -638,12 +638,14 @@ class CloudConnector:
from fluksio.api.deps import user_from_token
from fluksio.api.routes.flows import (
device_of,
event_for_panel,
panel_scope,
snapshot_payload,
)
from fluksio.api.socket_auth import redeem_ticket
from fluksio.core.db import engine
from fluksio.flow.devices import presence
from fluksio.flow.events import event_bus
stream_id = str(frame["id"])
@@ -662,12 +664,14 @@ class CloudConnector:
await socket.send(_dump({"op": "ws_close", "id": stream_id, "code": 1008}))
return
with Session(engine) as session:
if user_from_token(session, token) is None:
if user_from_token(session, token, app=self._app) is None:
await socket.send(
_dump({"op": "ws_close", "id": stream_id, "code": 1008})
)
return
only = panel_scope(token, self._app)
# A remote device is online for as long as this stream is open.
device = device_of(token, self._app) if only is not None else ""
await socket.send(_dump({"op": "ws_open_ok", "id": stream_id}))
@@ -683,6 +687,8 @@ class CloudConnector:
)
)
if device:
presence.opened(device)
try:
async with event_bus.subscribe() as queue:
while True:
@@ -719,6 +725,9 @@ class CloudConnector:
await socket.send(
_dump({"op": "ws_close", "id": stream_id, "code": 1011})
)
finally:
if device:
presence.closed(device)
async def _hook_stream(
self, socket: Any, stream_id: str, path: str, query: str