Plant devices (binding)
Since ADR 0012 this server keeps one piece of device data: which device serials belong to which plant (the binding). Everything else about a device — its record, model, status, topology, register reads and writes, commands and firmware — belongs to the TCP Server and is reached from the app over the WebSocket.
Three routes, all on the plant:
| Route | Purpose |
|---|---|
GET /v1/plants/{plantId}/devices | List the plant's bound serials (D01) |
POST /v1/plants/{plantId}/devices | Bind a serial to the plant (D02) |
DELETE /v1/plants/{plantId}/devices/{serial} | Unbind a serial (new) |
:::warning Not executed against a deployment
The device-ownership move (ADR 0012, change-plan phases 1–4) is code
complete and unit-tested but not deployed. Every request/response below is an illustrative example
derived from packages/core/src/plants/device-bindings.ts and the handlers
list-devices.ts, claim-device.ts, unbind-device.ts; none is a captured
execution.
:::
ADR 0012: what changed
- D01/D02 keep their paths and the five shipped mobile fields (
serial,plantId,model?,label?,createdAt). The 005 registry fields (deviceId,type,modelId,parentDeviceId,registrationState,bindingState) are no longer returned. Ignore them if an old build expects them. - The binding is keyed by the normalised serial; there is no device ULID any more. The serial is the one identity both servers share.
- D02's
typefield is accepted and ignored.modelis free text. - The web-console registry routes (inventory, transfers, imports, catalog, commands, bulk tasks, firmware, device files) are removed; their pages are kept as stubs under "Removed:" at the bottom of the sidebar.
App flow: claim here, then register with TCP
:::warning Deprecated since 2026-11-05 (ADR 0018 §Transition)
POST /v1/plants/{plantId}/devices and DELETE /v1/plants/{plantId}/devices/{serial}
are deprecated. TCP owns binding: bind with the TCP WebSocket (mobile register,
console bind_device / unbind_device), and this server follows TCP's
device.binding.changed.v1 within seconds. Both routes still work exactly as below —
same status and error codes, because shipped app versions call them — and now also
return Deprecation: @1793836800 (RFC 9745) on success and log deprecated_route_called.
They will be removed in a separate change once the logs show no caller. New app code
should not call them; GET /v1/plants/{plantId}/devices is not deprecated.
:::
The two servers never talk to each other about bindings, so the app tells both (ADR 0012 D1):
- Claim —
POST /v1/plants/{plantId}/devices { serial }.201(new) or200(already on this plant) both mean "bound here". - Register with TCP — send the device registration over the TCP
WebSocket (see the TCP Server docs). The realtime ticket from
POST /v1/realtime/ticketscarries the plant access levels TCP checks. - If step 2 fails, keep the binding and show a retry / re-sync
action; repeating step 1 is safe (
200, no write). - Re-sync when they disagree — compare D01's serial list with what TCP reports for the plant: claim serials TCP has but this server lacks; unbind (or re-register with TCP) serials only one side has.
- Remove —
DELETE /v1/plants/{plantId}/devices/{serial}here, then remove the device on the TCP side.
:::info Parallel inverters are decided by TCP, not here (2026-11-23)
TCP now refuses a second inverter on a plant unless the client sends parallel: true and both units are Nexus
inverters with an identical model code (refusal codes PARALLEL_CONFIRMATION_REQUIRED, PARALLEL_NOT_SUPPORTED,
PARALLEL_SPEC_UNKNOWN, PARALLEL_SPEC_MISMATCH). See the TCP Server docs: Device registration and Parallel
inverters. This server does not apply that rule. A 201/200 from the deprecated claim route above, or a
REGISTERED staged device from plant create, does not mean TCP accepted the inverter. Treat TCP's reply as the
answer. If TCP refuses, this server's binding is corrected by TCP's next device.binding.changed.v1 for that
device, or removed with DELETE above.
:::
Web console: Device Inventory actions (ADR 0018)
The web console's Device Inventory is served by the TCP Server. ADR 0018 (accepted 2026-11-04): TCP is the
source of truth for which plant a device is on. This server's binding follows TCP's device.binding.changed.v1
events (see Integration bus → Inbound binding events).
- Once both servers are deployed with it on a stage, the console calls TCP only for bind, unbind, transfer and remove. A binding moved by a transfer follows here within seconds. That includes a transfer to a plant in another Business, which the console could never mirror correctly.
- Transfers are immediate (issue #26). TCP's
request_device_transfermoves the device at once; there is no pending or accept step. TCP decides who may transfer, not this server. Its #26 change limits moves to another Business to a Super Admin or Administrator of the PLATFORM org; see the TCP Server documentation for the rules that are deployed. This server sees each transfer as onedevice.binding.changed.v1event withreason: TRANSFER. Moving into a plant binds the device there. Moving into a Business's unbound stock (plantId: null) deletes the binding and frees its serial guard. - On dev this is live (both servers deployed, first sync completed 2026-11-04). Console request 2026-11-20 §2
(confirmed in code 2026-11-23): the console calls TCP only for bind and unbind. Drop the
POST /v1/plants/{plantId}/devices/DELETE …/devices/{serial}call and the logic that reverses it when TCP fails: TCP's outbox is the reconciliation. TCP'sbind_device,unbind_deviceand bulk unbind all changedevices.plant_id, and a trigger queuesdevice.binding.changed.v1in the same transaction. The consumer (packages/core/src/plants/binding-from-tcp.ts) writes the samePLANT#<p>/DEVICE#…binding andSERIALBIND#guard these routes write. It is seq-guarded per device (TCPDEVICE#<deviceId>/BINDING, applied only whenlastSeq < seq). - Known gap: a binding written through these routes for a device TCP never sends an event about (for example, a TCP bind that failed and was never retried) stays until TCP emits an event for that serial. No sweeper removes it. Once the console stops calling these routes, only the deprecated mobile route can create one.
- Staging and prod are out of scope (dev is the only stage).
- The mobile app's routes stay. A binding written through them has no TCP version, so TCP's next event for that device wins.
- Fields on a binding TCP wrote: it carries
tcpDeviceIdandtcpVersion(not returned by D01/D02).createdByistcpwhen the consumer created it.labelandmodelcome from TCP.
Serial normalisation
The serial is stored as typed (trimmed) and compared on its normalised
form: NFKC, trimmed, upper-cased, spaces and - removed; . and _ kept.
The normalised serial must be 3–64 characters of [A-Z0-9._].
- New claims:
SN-1A,sn 1aandSN1Aare the same device, on any plant (theSERIALBIND#guard enforces it). - Legacy items (pre-005 claims, keyed by the raw serial), same plant: a
legacy item and a normalised claim of the same serial are one binding —
the claim answers
200. - Legacy items, across plants: no uniqueness guard yet. Two plants can hold the same device until the owner runs the guard backfill (KI-36). Don't assume a serial appears on only one plant for old data.
GET /v1/plants/{plantId}/devices — List devices of a plant
- HTTP method:
GET - Endpoint:
/v1/plants/{plantId}/devices - Authentication: Required (Cognito access token)
- Authorization:
devices ≥ VIEWon the plant (any legacy roleOWNER/ADMIN/VIEWERqualifies). No access path at all →403 FORBIDDEN"You do not have access to this plant" (legacy mobile contract, owner decision Q16/Q8; also for a plant id that does not exist); visible plant belowVIEW→403.
Request
Headers: Authorization: Bearer <token>.
Path parameters: plantId (string, required).
Query parameters (lenient route, CR-13 — unknown parameters ignored):
| Param | Type | Required | Default | Validation |
|---|---|---|---|---|
limit | integer | No | 25 | 1–50; a bad value silently falls back to 25 |
cursor | string | No | — | Opaque; a malformed or foreign cursor restarts from page 1 |
Response
{
items: Array<{
serial: string; // as typed when bound
plantId: string;
model?: string; // free text from the claim
label?: string;
createdAt: string; // ISO-8601 UTC
deviceId?: string; // ADR 0020 (additive): TCP's device id when TCP owns the binding
}>;
nextCursor?: string; // omitted on the last page
}
For a binding TCP owns, serial is the device's primary serial (inverter serial, else logger id), and
DELETE …/devices/{serial} accepts either the logger id or the inverter serial.
Order is the binding's sort key (normalised serial; pre-005 legacy rows by
their raw serial), not claim time. An empty plant returns { "items": [] }.
A page can hold fewer than limit items while nextCursor is present — keep
paging on nextCursor.
Legacy items: pre-005 claim items have the same key shape and are listed as bindings unchanged (no migration).
DynamoDB: access evaluation, then one Query on
PK=PLANT#<plantId>, SK begins_with DEVICE# filtered to bindings.
Successful response — illustrative example
{
"items": [
{
"serial": "SN-2K4A-001",
"plantId": "01J9Z4A1B2C3D4E5F6G7H8J9K0",
"model": "Aotai Hybrid 5K",
"label": "Roof array",
"createdAt": "2026-10-26T06:00:00.000Z"
}
]
}
HTTP status codes
| Status | code | When |
|---|---|---|
| 200 | — | Success (including an empty list) |
| 401 | — (gateway body {"message":"Unauthorized"}) | Missing/invalid token |
| 403 | FORBIDDEN | Visible plant, devices level below VIEW |
| 403 | FORBIDDEN | No access path to plantId (wrong or nonexistent plant): "You do not have access to this plant" |
| 410 | GONE | Plant is being deleted |
| 500 | INTERNAL | Unexpected error |
POST /v1/plants/{plantId}/devices — Claim a device serial
Deprecated (2026-11-05): see the note under App flow.
Purpose: binds a serial to the plant. One plant per serial, enforced atomically by a serial guard item. It never talks to the device or TCP.
- HTTP method:
POST - Endpoint:
/v1/plants/{plantId}/devices - Authentication: Required
- Authorization:
devices ≥ EDITon the plant (legacyOWNER/ADMINqualify,VIEWERdoes not). No access path →403 FORBIDDEN"You do not have access to this plant" (legacy mobile contract, owner decision Q16/Q8; also for a plant id that does not exist); visible plant belowEDIT→403. An End User connected to a Business holdsdevices: VIEWon its plants (RBAC-S12, 2026-11-24), so this is403for them: the Business or its Installer binds and removes devices.
Request
Headers: Authorization: Bearer <token> (required); Idempotency-Key
(optional). Any Content-Type is accepted.
Path parameters: plantId (string, required).
Body (ClaimDeviceInput) — lenient, unknown fields dropped:
| Field | Type | Required | Validation |
|---|---|---|---|
serial | string | Yes | Trimmed, 3–64 chars, ^[A-Za-z0-9._ -]+$; then the normalised form must be 3–64 of [A-Z0-9._] |
model | string | No | Trimmed, ≤ 80; null/"" = unset |
label | string | No | Trimmed, ≤ 120; null/"" = unset |
type | enum | No | INVERTER, LOGGER, METER, BATTERY, OTHER — accepted and ignored |
{ "serial": "SN-2K4A-001", "model": "Aotai Hybrid 5K", "label": "Roof array" }
Order of checks:
- Body shape →
422 VALIDATION_FAILED. - Normalised serial format →
422 VALIDATION_FAILED,details.field = "serial",details.reason=TOO_SHORT|TOO_LONG|INVALID_CHARACTERS. - Access →
403(no access path, including a nonexistent plant, ordevicesbelowEDIT). - Plant archived, being deleted or already deleted →
409 INVALID_STATE,details.reason = "PLANT_NOT_BINDABLE". - Already bound to this plant →
200with the stored binding (no write; the storedlabel/modelare kept, the new ones ignored). - Bound to another plant (live guard, or a pre-005 legacy claim item on
another plant) →
409 CONFLICT. - One transaction: binding +
SERIALBIND#guard + plant bindability check + delete of the dashboard "setup incomplete" marker + the idempotency marker →201. A lost race is re-read once and answered as in 5/6.
The plant's deviceCount follows from the DynamoDB stream.
Response
The binding (same shape as a D01 item). 201 new, 200 already here.
201 Created — illustrative example
{
"serial": "SN-2K4A-001",
"plantId": "01J9Z4A1B2C3D4E5F6G7H8J9K0",
"model": "Aotai Hybrid 5K",
"label": "Roof array",
"createdAt": "2026-10-26T10:05:00.000Z"
}
Idempotent replay: the same Idempotency-Key and body returns 201 with
the binding as stored now and Idempotent-Replayed: true; if it has been
unbound since, 404 NOT_FOUND.
Failure responses — illustrative
{ "error": { "code": "VALIDATION_FAILED", "message": "serial is not a valid device serial", "details": { "field": "serial", "reason": "TOO_SHORT" } } }
{ "error": { "code": "CONFLICT", "message": "Device already claimed by another plant" } }
{ "error": { "code": "INVALID_STATE", "message": "The plant is archived or being deleted", "details": { "reason": "PLANT_NOT_BINDABLE" } } }
{ "error": { "code": "FORBIDDEN", "message": "You do not have permission to add devices to this plant" } }
HTTP status codes
| Status | code | When |
|---|---|---|
| 200 | — | Serial already on this plant (idempotent re-claim, KI-8 fixed) |
| 201 | — | Bound, or a replay (Idempotent-Replayed: true) |
| 401 | — (gateway body) | Missing/invalid token |
| 403 | FORBIDDEN | Visible plant, devices below EDIT |
| 403 | FORBIDDEN | No access path to plantId (including a nonexistent plant) |
| 404 | NOT_FOUND | A replay after unbind |
| 409 | CONFLICT | Serial bound to another plant |
| 409 | INVALID_STATE | details.reason = PLANT_NOT_BINDABLE — archived, deleting or deleted plant |
| 409 | IDEMPOTENCY_IN_PROGRESS | Same key still being processed |
| 413 | PAYLOAD_TOO_LARGE | Body over 256 KiB |
| 422 | VALIDATION_FAILED | Body or serial invalid |
| 422 | IDEMPOTENCY_KEY_REUSED | Same Idempotency-Key sent with a different body |
| 500 | INTERNAL | Unexpected error |
| 503 | DEPENDENCY_UNAVAILABLE | DynamoDB throttled/unavailable; Retry-After |
DELETE /v1/plants/{plantId}/devices/{serial} — Unbind a device serial
Deprecated (2026-11-05): see the note under App flow.
- HTTP method:
DELETE - Endpoint:
/v1/plants/{plantId}/devices/{serial} - Authentication: Required
- Authorization: same as D02 —
devices ≥ EDIT; no access path →404, belowEDIT→403.
Request
Headers: Authorization: Bearer <token>. No If-Match (a binding has no
version to guard), no Idempotency-Key, no body.
Path parameters:
| Param | Type | Notes |
|---|---|---|
plantId | string | Required |
serial | string | As typed or normalised (URL-encode spaces). A legacy row is matched by its raw serial. Empty or over 128 chars → 404 |
Response
204 No Content. The binding and its serial guard are deleted in one
transaction; the serial can then be claimed on any plant.
HTTP status codes
| Status | code | When |
|---|---|---|
| 204 | — | Unbound |
| 401 | — (gateway body) | Missing/invalid token |
| 403 | FORBIDDEN | Visible plant, devices below EDIT |
| 404 | NOT_FOUND | No access path to the plant; or the serial is not bound to this plant (including a repeated or concurrent DELETE) |
| 409 | INVALID_STATE | details.reason = PLANT_NOT_BINDABLE — archived, deleting or deleted plant |
| 500 | INTERNAL | Unexpected error |
| 503 | DEPENDENCY_UNAVAILABLE | DynamoDB throttled/unavailable |
{ "error": { "code": "NOT_FOUND", "message": "Device not found" } }
Edge cases
- Same serial twice on one plant (any spelling variant):
200with the existing binding; nothing written. Safe to retry after a timeout. - Bound elsewhere:
409 CONFLICT. The app should tell the user the device is on another plant; there is no transfer route — the other plant must unbind it first. - Concurrent claims of one serial on different plants: exactly one
201, the rest409(KI-9 fixed by the guard). - Archived plant: claim and unbind both answer
409 INVALID_STATE PLANT_NOT_BINDABLE; the list still works. A plant being deleted answers410on the list. - Legacy items (pre-005 claims): listed as bindings unchanged, and can be unbound by their raw serial. They have no guard item until the backfill runs; a new claim finds them through GSI1 (eventually consistent, best effort), so two pre-existing legacy claims on different plants are not detected (KI-36).
- Deleted plant: when a plant enters deletion every binding and its
guard are removed (25 per transaction, retried one at a time), so its
serials become claimable again; a guard left pointing at a binding that no
longer exists is stale and is replaced by the next claim. Plant deletion lists the plant's
serials in
plant.deletion.requested.v1(serials) for TCP. - Invalid body beats access: an invalid body returns
422even without access to the plant. - Work orders name a device by its bound serial (
deviceSerial) — see Service work orders.