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
+11 -35
View File
@@ -1,5 +1,4 @@
import { expect, type Page, test } from "@playwright/test"
import type { PanelDef } from "../src/client"
import { api, apiPage, deleteAll } from "./utils/api"
/**
@@ -17,8 +16,6 @@ import { api, apiPage, deleteAll } from "./utils/api"
const flowName = `test_panel_${Date.now().toString(36)}`
const first = `${flowName}_a`
const second = `${flowName}_b`
/** The instance's own panels, put back by the teardown. */
let panels: PanelDef[] | null = null
test.use({ storageState: "playwright/.auth/user.json" })
test.describe.configure({ mode: "serial" })
@@ -92,36 +89,20 @@ test.beforeAll(async ({ browser }) => {
})
}
// Saving is a whole-list replace, and a panel that disappears takes the
// credential of the screen hanging on it. So append to what is there, and
// keep the list for the teardown to put back.
const config = await (await api(page, "/panels/")).json()
const existing: PanelDef[] = (config.panels ?? []).filter(
(p: PanelDef) => p.id !== flowName,
)
panels = existing
await api(page, "/panels/", {
// A device of its own, saved on its own: nothing else on the instance moves.
const device = await (
await api(page, `/devices/${flowName}`, { method: "POST" })
).json()
await api(page, `/devices/${flowName}`, {
method: "PUT",
data: {
panels: [
...existing,
{ id: flowName, title: "Hall", dashboards: [first, second] },
],
version: config.version,
},
data: { ...device, title: "Hall", dashboards: [first, second] },
})
await page.close()
})
test.afterAll(async ({ browser }) => {
// Restoring the list is also what removes this spec's own panel.
if (panels) {
const page = await apiPage(browser)
const { version } = await (await api(page, "/panels/")).json()
await api(page, "/panels/", { method: "PUT", data: { panels, version } })
await page.close()
}
await deleteAll(browser, [
`/devices/${flowName}`,
`/dashboards/${first}`,
`/dashboards/${second}`,
`/flows/${flowName}`,
@@ -233,17 +214,12 @@ test("a touched panel grows its rail without widening it", async ({ page }) => {
await setTouch(page, false)
})
/** What the Panels dialog writes, as the API sees it. */
/** What the device's Touch friendly switch writes, as the API sees it. */
async function setTouch(page: Page, touch: boolean) {
const config = await (await api(page, "/panels/")).json()
await api(page, "/panels/", {
const device = await (await api(page, `/devices/${flowName}`)).json()
await api(page, `/devices/${flowName}`, {
method: "PUT",
data: {
panels: (config.panels ?? []).map((panel: PanelDef) =>
panel.id === flowName ? { ...panel, touch } : panel,
),
version: config.version,
},
data: { ...device, touch },
})
}