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:
@@ -87,9 +87,16 @@ def _device_messages(device: DeviceDef, request: Request) -> set[str]:
|
||||
the answer to give when the answer cannot be worked out.
|
||||
"""
|
||||
store: DashboardStore | None = getattr(request.app.state, "dashboard_store", None)
|
||||
if store is None:
|
||||
owned: DeviceStore | None = getattr(request.app.state, "device_store", None)
|
||||
if store is None or owned is None:
|
||||
return set()
|
||||
return devices.messages_for(device, store)
|
||||
return devices.messages_for(device, store, owned)
|
||||
|
||||
|
||||
def _device_in(device: DeviceDef, request: Request) -> set[str]:
|
||||
"""The messages this device's own ``in`` ports are wired to publish."""
|
||||
owned: DeviceStore | None = getattr(request.app.state, "device_store", None)
|
||||
return devices.io_in(device, owned) if owned is not None else set()
|
||||
|
||||
|
||||
def _locked(defn: DashboardDef, live: dict[str, Any]) -> bool:
|
||||
@@ -128,14 +135,15 @@ def _device_writable(device: DeviceDef, request: Request) -> set[str]:
|
||||
one is what entitles the screen to it. Reads are untouched — read-only is
|
||||
not blind, and a locked dashboard has to keep drawing live data.
|
||||
|
||||
The panel's own ``in`` ports are added outside the lock: it covers the
|
||||
controls on a dashboard, not the sensors on the device. Its ``out`` ports
|
||||
are read, not written, unless a widget targets them too.
|
||||
The device's own ``in`` ports, as flows wire them, are added outside the
|
||||
lock: it covers the controls on a dashboard, not the sensors on the
|
||||
device. Its ``out`` ports are read, not written, unless a widget targets
|
||||
them too.
|
||||
"""
|
||||
store: DashboardStore | None = getattr(request.app.state, "dashboard_store", None)
|
||||
if store is None:
|
||||
return set()
|
||||
writable = devices.io_in(device)
|
||||
writable = _device_in(device, request)
|
||||
defns = devices.dashboards_for(device, store)
|
||||
bound = sorted(
|
||||
{s.message for d in defns if (s := d.settings.get("locked")) and s.message}
|
||||
@@ -197,11 +205,18 @@ def _device_may(payload: dict[str, Any], request: Request) -> None:
|
||||
a panel to read every message it names and to publish to none of them but
|
||||
the requests its own charts ask by.
|
||||
|
||||
Its own ports are the device nodes the published flows hold for it, so
|
||||
wiring a port in a flow is what lets the device publish on it.
|
||||
|
||||
The device is left on ``request.state`` for the route, which credits a
|
||||
value published on one of its ports to the node holding that port.
|
||||
|
||||
# ponytail: the device file, its nonce and the published dashboards are
|
||||
# re-read per request. Cache them behind the store's revision if this
|
||||
# shows up in a profile.
|
||||
"""
|
||||
device = _device_for(payload, request.app)
|
||||
request.state.device = device
|
||||
|
||||
api = settings.API_V1_STR
|
||||
path = request.url.path
|
||||
@@ -252,7 +267,7 @@ def _device_may(payload: dict[str, Any], request: Request) -> None:
|
||||
elif method == "PUT" and path == f"{api}/artifacts":
|
||||
# What the device's own sensor recorded — a microphone's utterance —
|
||||
# uploaded under the ``in`` message it is about to publish it to.
|
||||
allowed = request.query_params.get("name", "") in devices.io_in(device)
|
||||
allowed = request.query_params.get("name", "") in _device_in(device, request)
|
||||
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user