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
+3 -3
View File
@@ -512,10 +512,10 @@ function FlowEditorInner({
params: { name: (rest ?? "").split(":")[0] },
})
} else if (kind === "panel") {
// A panel has no page of its own, only its row in the Panels dialog.
// A device's own port: its page in the Devices tab.
navigate({
to: "/dashboards",
search: { panels: true, panel: (rest ?? "").split(":")[0] },
to: "/devices/$id",
params: { id: (rest ?? "").split(":")[0] },
})
} else if (kind === "flow") {
navigate({
+17 -4
View File
@@ -3,7 +3,8 @@ import { useQueryClient } from "@tanstack/react-query"
import { useEffect } from "react"
import { ApiError, FlowsService, OpenAPI } from "@/client"
import { dashboardKeys, panelKeys } from "@/components/Dashboard/queries"
import { dashboardKeys } from "@/components/Dashboard/queries"
import { deviceKeys } from "@/components/Devices/queries"
import { healthKeys } from "@/components/Health/queries"
import { runKeys } from "@/components/Runs/queries"
import { connectionStore } from "@/lib/connectionStore"
@@ -111,6 +112,13 @@ type FlowEvent =
paused?: string[]
}
| { type: "dashboard_changed"; dashboard?: string; ts?: number }
| {
type: "device_status"
device: string
online: boolean
last_seen?: string | null
ts?: number
}
| {
type: "run_started" | "run_finished"
flow: string
@@ -258,7 +266,7 @@ function open(url: string) {
for (const queryKey of [
flowKeys.all,
dashboardKeys.all,
panelKeys.all,
deviceKeys.all,
runKeys.all,
healthKeys.all,
]) {
@@ -399,7 +407,7 @@ function open(url: string) {
client?.invalidateQueries({ queryKey: flowKeys.all })
break
case "dashboard_changed":
// Someone published, or changed which dashboards a panel shows. Refetch
// Someone published, or changed which dashboards a device shows. Refetch
// rather than reload: a wall screen must not blank or sign in again.
// `exact` matters — the list key is a prefix of every detail key,
// including the draft an editor may have open.
@@ -407,9 +415,14 @@ function open(url: string) {
client?.invalidateQueries({
queryKey: message.dashboard
? dashboardKeys.detail(message.dashboard)
: panelKeys.all,
: deviceKeys.all,
})
break
case "device_status":
// A device's socket opened or closed: the Devices tab reads presence
// off the list.
client?.invalidateQueries({ queryKey: deviceKeys.all, exact: true })
break
case "run_started":
case "run_finished":
// One invalidation covers the lot: the list, the flow counts, the run