Capability report: PUT /devices/{id}/report, a Capabilities section, offline devices degraded
A device reports its board, screen, camera and ports from its own credential (16 KB, schema 1, replacing the last report), and the flows are validated against it again. The node panel turns a reported port's config schema into a form, a reported screen is a canvas preset and a touch screen's first report turns Touch friendly on. An offline device node is degraded: amber on the canvas, a warning on Home, never a fault. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0138N7k5PT4dcR1iEqXaaQ9k
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a9d453c9d9
commit
ad76200d3d
@@ -27,10 +27,10 @@ import {
|
||||
} from "@/client"
|
||||
import {
|
||||
DEVICE_TYPE,
|
||||
PORT_SUGGESTIONS,
|
||||
portOf,
|
||||
type ReportedPort,
|
||||
reportedPorts,
|
||||
wiresAs,
|
||||
} from "@/components/Devices/ports"
|
||||
import { devicesQueryOptions } from "@/components/Devices/queries"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -637,8 +637,7 @@ function DevicePortList({
|
||||
onChange: (next: MessageSpec[], renamed?: [string, string | null]) => void
|
||||
onConfig: (port: string, next: Record<string, unknown>) => void
|
||||
}) {
|
||||
const offered = reported?.filter((port) => port.direction === direction)
|
||||
const listId = `device-ports-${direction}`
|
||||
const offered = reported?.filter((port) => wiresAs(port, direction))
|
||||
// An out port is read when the device asks for it, never a reason to run.
|
||||
const fresh = (port: ReportedPort | null): MessageSpec => ({
|
||||
name: port ? port.port.replace(/\./g, "_") : "",
|
||||
@@ -670,17 +669,19 @@ function DevicePortList({
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
<datalist id={listId}>
|
||||
{PORT_SUGGESTIONS.map((port) => (
|
||||
<option key={port} value={port} />
|
||||
))}
|
||||
</datalist>
|
||||
{specs.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No ports yet.</p>
|
||||
) : null}
|
||||
{specs.map((spec, index) => {
|
||||
const port = spec.port ?? ""
|
||||
const name = port || "new port"
|
||||
const said = reported?.find((one) => one.port === port)
|
||||
// The device says which settings it reads, so they get a form.
|
||||
const schema =
|
||||
said?.config &&
|
||||
Object.keys((said.config.properties as object) ?? {}).length
|
||||
? said.config
|
||||
: undefined
|
||||
return (
|
||||
<div key={`port-${index}`} className="grid min-w-0 gap-1.5">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
@@ -730,7 +731,6 @@ function DevicePortList({
|
||||
placeholder="Port, e.g. gpio.4"
|
||||
aria-label={`Port of ${name}`}
|
||||
autoComplete="off"
|
||||
list={listId}
|
||||
className="h-8 min-w-0 flex-1 font-mono text-sm"
|
||||
onBlur={(event) => {
|
||||
const next = portOf(event.currentTarget.value)
|
||||
@@ -792,16 +792,35 @@ function DevicePortList({
|
||||
autoFocus={false}
|
||||
onChange={(next) => update(index, { name: next })}
|
||||
/>
|
||||
<JsonField
|
||||
value={config[port] ?? {}}
|
||||
label={`Config of ${name}`}
|
||||
check={objectOnly}
|
||||
className="h-8 w-24 shrink-0"
|
||||
onChange={(next) => {
|
||||
if (port) onConfig(port, next as Record<string, unknown>)
|
||||
}}
|
||||
/>
|
||||
{schema ? null : (
|
||||
<JsonField
|
||||
value={config[port] ?? {}}
|
||||
label={`Config of ${name}`}
|
||||
check={objectOnly}
|
||||
className="h-8 w-24 shrink-0"
|
||||
onChange={(next) => {
|
||||
if (port) onConfig(port, next as Record<string, unknown>)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{reported && port && !said ? (
|
||||
<p className="pl-5.5 text-xs text-muted-foreground">
|
||||
The device does not report this port.
|
||||
</p>
|
||||
) : null}
|
||||
{schema ? (
|
||||
<div className="pl-5.5">
|
||||
<ParamsForm
|
||||
type={undefined}
|
||||
title={`${port} settings`}
|
||||
schema={schema}
|
||||
params={(config[port] ?? {}) as Record<string, unknown>}
|
||||
provides={[]}
|
||||
onChange={(next) => onConfig(port, next)}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
@@ -1120,12 +1139,14 @@ function InjectPayloads({
|
||||
/** A small form built from the node type's declared parameters. */
|
||||
function ParamsForm({
|
||||
type,
|
||||
title = "Settings",
|
||||
schema,
|
||||
params,
|
||||
provides,
|
||||
onChange,
|
||||
}: {
|
||||
type: string | undefined
|
||||
title?: string
|
||||
schema: Record<string, unknown> | undefined
|
||||
params: Record<string, unknown>
|
||||
/** The ports an inject's payload fields follow; unused by every other type. */
|
||||
@@ -1139,6 +1160,7 @@ function ParamsForm({
|
||||
title?: string
|
||||
description?: string
|
||||
default?: unknown
|
||||
enum?: unknown[]
|
||||
"x-secret"?: boolean
|
||||
}
|
||||
>
|
||||
@@ -1161,7 +1183,7 @@ function ParamsForm({
|
||||
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
<span className={SECTION}>Settings</span>
|
||||
<span className={SECTION}>{title}</span>
|
||||
{entries.map(([key, property]) => {
|
||||
// In the schema's own place, so the payload keeps its position in the
|
||||
// form even though it is now one field per port.
|
||||
@@ -1261,6 +1283,37 @@ function ParamsForm({
|
||||
)
|
||||
}
|
||||
|
||||
// A closed set of choices, such as a pin's pull.
|
||||
if (property.enum?.length) {
|
||||
return (
|
||||
<div key={key} className="grid gap-1.5">
|
||||
<FieldLabel htmlFor={`param-${key}`} help={property.description}>
|
||||
{label}
|
||||
</FieldLabel>
|
||||
<Select
|
||||
value={String(value)}
|
||||
onValueChange={(next) =>
|
||||
set(
|
||||
key,
|
||||
property.enum?.find((choice) => String(choice) === next),
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger id={`param-${key}`} className="!h-8 text-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{property.enum.map((choice) => (
|
||||
<SelectItem key={String(choice)} value={String(choice)}>
|
||||
{String(choice)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const numeric =
|
||||
property.type === "integer" || property.type === "number"
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user