Device node: a device's ports are wired in flows

- flow/nodes/device.py: `device` node with params `device` and `config`;
  provides the device's `in` ports, requires its `out` ports without
  waking anything, never run (Node.passive), down "Offline" from presence
- DeviceDef.io and DevicePort go; GET /devices/{id} computes `io` and
  `bindings` from the device nodes of published flows, in a fixed order,
  cached by FlowStore.revision; the credential's scope comes from them
- issues `unknown_device` and `device_port` (wired twice; against a report
  the wrong direction or dtype, or unlisted as advisory), rechecked when a
  device is created or deleted; ValidationIssue.advisory is a field
- a device publishing on a bound port is credited to its node by the
  server; the panel endpoint kind is gone from `_endpoints` and the canvas
- a rebuild that moves a device's bindings sends `dashboard_changed` with
  an empty name, which the firmware refetches on
- startup moves each device's `io` rows into device nodes in the flows
  declaring their messages, draft and published, one commit; rows no
  flow declares are logged and left out
- frontend: Device node settings (device, Publishes, Follows, a port
  picker from a report), palette shortcuts per reported port, DeviceDetail
  lists bindings with "Use in flow" in place of the I/O editor
- docs: devices, flow editor, node types, issues, API
This commit is contained in:
Melvin Strobl
2026-10-16 16:40:31 +02:00
parent 91e3b703f9
commit 29d3ec467f
35 changed files with 2195 additions and 494 deletions
+116 -28
View File
@@ -911,6 +911,36 @@ export const DeadLetterSchema = {
title: 'DeadLetter'
} as const;
export const DeviceBindingSchema = {
properties: {
flow: {
type: 'string',
title: 'Flow'
},
node: {
type: 'string',
title: 'Node'
},
port: {
type: 'string',
title: 'Port'
},
message: {
type: 'string',
title: 'Message'
},
direction: {
type: 'string',
enum: ['in', 'out'],
title: 'Direction'
}
},
type: 'object',
required: ['flow', 'node', 'port', 'message', 'direction'],
title: 'DeviceBinding',
description: 'Where a port is wired: the device node holding it.'
} as const;
export const DeviceCreateSchema = {
properties: {
title: {
@@ -946,13 +976,6 @@ export const DeviceDefSchema = {
title: 'Touch',
default: false
},
io: {
items: {
'$ref': '#/components/schemas/DevicePort'
},
type: 'array',
title: 'Io'
},
version: {
type: 'integer',
title: 'Version',
@@ -965,7 +988,59 @@ export const DeviceDefSchema = {
description: 'One device, and what it shows.'
} as const;
export const DevicePortSchema = {
export const DeviceDocumentSchema = {
properties: {
id: {
type: 'string',
title: 'Id'
},
title: {
type: 'string',
title: 'Title',
default: ''
},
dashboards: {
items: {
type: 'string'
},
type: 'array',
title: 'Dashboards'
},
touch: {
type: 'boolean',
title: 'Touch',
default: false
},
version: {
type: 'integer',
title: 'Version',
default: 0
},
io: {
items: {
'$ref': '#/components/schemas/DeviceIo'
},
type: 'array',
title: 'Io'
},
bindings: {
items: {
'$ref': '#/components/schemas/DeviceBinding'
},
type: 'array',
title: 'Bindings'
}
},
type: 'object',
required: ['id'],
title: 'DeviceDocument',
description: `A device as it reads itself: what it shows, and what its ports carry.
\`\`io\`\` is worked out from the device nodes in published flows, in a fixed
order, so an unchanged state reads back as the same bytes.`
} as const;
export const DeviceIoSchema = {
properties: {
port: {
type: 'string',
@@ -988,12 +1063,8 @@ export const DevicePortSchema = {
},
type: 'object',
required: ['port', 'message', 'direction'],
title: 'DevicePort',
description: `One piece of the device's own hardware, wired to a message.
A wall panel is a node as well as a screen: a button on its GPIO, a
microphone, a speaker. Which ports exist is the device's business, so the
name is free text and \`\`config\`\` is passed through to it unread.`
title: 'DeviceIo',
description: 'One port as the device reads it: the message it publishes or follows.'
} as const;
export const DevicePublicSchema = {
@@ -1019,18 +1090,25 @@ export const DevicePublicSchema = {
title: 'Touch',
default: false
},
io: {
items: {
'$ref': '#/components/schemas/DevicePort'
},
type: 'array',
title: 'Io'
},
version: {
type: 'integer',
title: 'Version',
default: 0
},
io: {
items: {
'$ref': '#/components/schemas/DeviceIo'
},
type: 'array',
title: 'Io'
},
bindings: {
items: {
'$ref': '#/components/schemas/DeviceBinding'
},
type: 'array',
title: 'Bindings'
},
online: {
type: 'boolean',
title: 'Online',
@@ -1047,6 +1125,18 @@ export const DevicePublicSchema = {
}
],
title: 'Last Seen'
},
report: {
anyOf: [
{
additionalProperties: true,
type: 'object'
},
{
type: 'null'
}
],
title: 'Report'
}
},
type: 'object',
@@ -1125,9 +1215,8 @@ export const EndpointSchema = {
title: 'Endpoint',
description: `Something wired into this flow that is not a node in it.
A dashboard control setting one of its messages, a tile showing one, a
port on a panel's own hardware, or a node in another flow on the far side
of a dotted name. The canvas draws these so a value never appears to come
A dashboard control setting one of its messages, a tile showing one, or a
node in another flow on the far side of a dotted name. The canvas draws these so a value never appears to come
from nowhere — or worse, appears to come from whichever node happens to be
drawn as a producer.`
} as const;
@@ -4638,7 +4727,7 @@ export const ValidationIssueSchema = {
properties: {
code: {
type: 'string',
enum: ['cycle', 'unconnected_input', 'missing_initial_value', 'node_error', 'unauthenticated_hook', 'self_loop_needs_initial', 'missing_source', 'node_unhealthy', 'ignored_device'],
enum: ['cycle', 'unconnected_input', 'missing_initial_value', 'node_error', 'unauthenticated_hook', 'self_loop_needs_initial', 'missing_source', 'node_unhealthy', 'ignored_device', 'unknown_device', 'device_port'],
title: 'Code'
},
message: {
@@ -4694,12 +4783,11 @@ export const ValidationIssueSchema = {
advisory: {
type: 'boolean',
title: 'Advisory',
description: 'Worth saying, but not a fault — the UI says so in a softer tone.',
readOnly: true
default: false
}
},
type: 'object',
required: ['code', 'message', 'advisory'],
required: ['code', 'message'],
title: 'ValidationIssue',
description: 'Something wrong with a flow — a fault, or merely advisory.'
} as const;