Device import and favourites: mobile app changes
From: backend (cse_tcp_be) · Date: 24 Nov 2026 Context: the owner asked for three things. When an Admin or Super Admin imports or registers a device, the server returns that device's details so the app opens it straight away, and the app can load its plant. A device an Admin or Super Admin imports, registers or looks up by its serial becomes their favourite. Favourites always appear first on the devices list, lazily loaded: the 15 most recent first, then 10 per load.
This page is what the Flutter app needs to build. Every message below is a
web console message on the same WebSocket the app
already uses, after auth with a realtime ticket.
:::caution Status The backend code is written and its unit tests pass. It is not deployed and not committed yet. Its database integration tests have not been run. See What is not done yet. Every JSON example on this page is illustrative: written from the server code, not captured from a live server. Field names and types are checked against the code; values are made up. :::
Full reference:
- Devices: every message used here, field by field
- Device Inventory:
import_devices - Web console overview: envelope, error codes, limits, paging
- Authentication: the realtime ticket every message here needs
- HTTP server:
GET /v1/plants/{plantId} - Support desk: find a device: the short search → details → plant → favourites flow for a support call
What changes for the user
| Screen | Today | After this change |
|---|---|---|
| Add device / batch import | The reply gives only a device id; the app must fetch the device | The reply carries the whole device; the app opens the device screen at once, and loads the plant from the HTTP server |
| Find a device by serial | Shows the device | Same, and for an Admin/Super Admin the device is starred automatically |
| Devices list | Favourites mixed in with the rest | Favourites pinned at the top: the 15 most recent, then "load more" 10 at a time, then the normal list |
| Favourites screen | 50 per page | 15 first, then 10 per load |
Request and reply envelope (applies to every task)
{"type": "register_device_web", "requestId": "rg-1", "...": "..."}
Success: {"type": "<type>_result", "requestId": "rg-1", "ok": true, "result": {…}}.
Failure: {"type": "<type>_result", "requestId": "rg-1", "ok": false, "code": "CONFLICT", "error": "…", "details": {"reason": "…"}}.
Match replies by requestId: replies can arrive in any order. At most
4 console requests can be in flight per connection; a fifth gets
BUSY. Branch on code and details.reason, never on error (a
human-readable sentence that can change). The codes are in the
overview.
Task 1: Who gets what
The server decides everything from the realtime ticket. Nothing in a request can claim a role.
| Caller | Import / register | Auto-favourite | Favourites pinned on the list |
|---|---|---|---|
Platform Super Admin (ticket claim sa) | Yes, into any plant they hold devices MANAGE on (their all grant gives every plant) | Yes | Yes |
Platform Administrator (ticket claim pa) | Same | Yes | Yes |
Other roles with a devices MANAGE grant (installer, operator, a Business Admin) | Yes, into plants where they hold devices MANAGE | No | Yes |
| Anyone else (e.g. a plain owner with no grant) | No: FORBIDDEN | No | Yes (their own manual favourites) |
MANAGEcomes from a ticket grant. Owning devices is not enough forimport_devicesorcheck_serial.register_device_webneeds devicesMANAGEon the target plant.- Auto-favourite is only for the platform Super Admin and Administrator.
A Business's own Admin or Super Admin (the ticket's
oaclaim) does not get it, and neither does any other role that sees every device (such as an auditor). Hide any "starred automatically" hint for them. - Opening a device does not star it. Only register, import and a lookup by the whole serial do.
- Pinned favourites are per user, for every user: each caller sees their own favourites first.
Task 2: Register one device, or import a file
2a. Register one device: register_device_web
{"type": "register_device_web", "requestId": "rg-1",
"loggerId": "M2506A0012", "inverterSn": "AT5K2400123",
"plantId": "01JPLANT00000000000000000A", "parallel": false}
| Field | Type | Required | Notes |
|---|---|---|---|
loggerId | string | yes | Letters, digits, -, _, .; stored lower case |
inverterSn | string | no | Stored upper case. Leave out to have it read from the hardware |
plantId | string | yes | Upper-cased by the server |
ownerSub | string | no | A user id (UUID). Used only when the server does not know the plant's owner yet. Default: you |
draftId | string | no | A registration draft to delete on success |
parallel | boolean | no | Default false. Send true only after the user confirms the inverter is wired in parallel with the plant's (parallel rules) |
Reply (illustrative):
{"type": "register_device_web_result", "requestId": "rg-1", "ok": true, "result": {
"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f",
"plantId": "01JPLANT00000000000000000A",
"device": {
"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f",
"type": "inverter",
"availableTypes": ["inverter"],
"loggerId": {"value": "m2506a0012", "source": "device"},
"inverterSn": {"value": "AT5K2400123", "source": "entered at registration, not yet confirmed by the hardware"},
"snVerification": "unverified",
"status": "pending_connection",
"plantId": "01JPLANT00000000000000000A",
"ownerOrgId": "01JORG0000000000000000000B",
"model": {"value": null, "reason": "the device's model is not identified yet (it is read on its first connection)"},
"hasBattery": false, "batteries": [], "batteryCount": 0,
"displayName": null,
"lastSeenAt": null,
"lastReadings": {"value": null, "reason": "no reading has been stored for this device yet"},
"registeredAt": "2026-11-24T09:14:00Z",
"updatedAt": "2026-11-24T09:14:00Z",
"...": "every other get_device_details field"
},
"favourite": true
}}
| Reply field | Type | Notes |
|---|---|---|
deviceKey | string (UUID) | The device id. Unchanged from before |
plantId | string | The plant. Unchanged from before |
device | object or null | New. Exactly the get_device_details result (inverter view), as you would see it. null only if the server could not read the device back after registering it |
favourite | boolean | New. The device is now one of your favourites |
warnings | string[] | New, optional. ["FAVOURITES_FULL"] when it was not starred because you already have 200 favourites |
Many device fields are {"value": …, "reason"?: …, "source"?: …}
objects. value is null with a reason when the server cannot fill it;
show the reason or a dash, never a made-up value. A brand-new device has
no model, readings or connection yet: that is normal until its logger
connects.
What the app does with the reply:
- Open the device screen with
result.device. Do not sendget_device_detailsagain. - If
result.deviceisnull, the device is registered. Open the device screen by sendingget_device_detailswithresult.deviceKey. Do not retry the registration: a retry fails withDEVICE_ALREADY_REGISTEREDorLOGGER_ALREADY_BOUND. - Load the plant with
result.plantId(Task 4). - Mark the device starred if
result.favouriteistrue. IfwarningscontainsFAVOURITES_FULL, show a one-line notice ("Not added to favourites: you already have 200. Remove one to make room."). Registration still succeeded. favourite: falsewith no warning: you are not a platform Super Admin or Administrator, or the star could not be saved. Do nothing special. The user can still star the device by hand (Task 6).
Errors. register_device_web has a 15 s limit. Failures carry
details.reason; the most common:
code | details.reason | Show |
|---|---|---|
FORBIDDEN | (none) | You need devices MANAGE on this plant |
FORBIDDEN | NOT_AUTHORIZED | The hardware is registered to another account |
FORBIDDEN | OWN_PLANTS_ONLY | The device belongs to another Business; transfer it instead |
CONFLICT | DEVICE_IN_ANOTHER_PLANT | The inverter is in another plant (existingPlantId, existingDeviceKey when you may see them) |
CONFLICT | LOGGER_ALREADY_BOUND | The logger is on another device |
CONFLICT | DEVICE_REVOKED | The device was taken out of service |
CONFLICT | DEVICE_ALREADY_REGISTERED | The inverter is registered with another logger |
CONFLICT | PARALLEL_* | The plant already has an inverter; see the parallel rules |
CONFLICT | (none, details.maxDevices) | The plant is full |
INVALID_REQUEST | (none) | A field is malformed (show the field, fix the input) |
UNAVAILABLE | (none) | Retry with backoff |
The full table is in register_device_web.
2b. Batch import: import_devices
Always run the file twice: first with dryRun: true to show the user what
will happen, then for real with the rows they keep.
{"type": "import_devices", "requestId": "im-1", "dryRun": true, "rows": [
{"loggerId": "y25319070301", "inverterSn": "CR60H2291905", "plantId": "01JPLANT00000000000000000A"},
{"loggerId": "y25319070302", "plantId": "01JPLANT00000000000000000B"}
]}
| Field | Type | Required | Notes |
|---|---|---|---|
rows | array | yes | 1–100 rows. Split a larger file |
rows[].loggerId, inverterSn, plantId, ownerSub, parallel | As for register_device_web | ||
dryRun | boolean | no | true checks every row and registers nothing |
Dry-run reply (illustrative; unchanged by this work):
{"type": "import_devices_result", "requestId": "im-1", "ok": true, "result": {
"dryRun": true, "ok": 1, "failed": 1, "results": [
{"row": 1, "loggerId": "y25319070301", "ok": true, "warnings": ["NOT_IN_FACTORY_RECORDS"]},
{"row": 2, "loggerId": "y25319070302", "ok": false, "code": "CONFLICT", "error": "…", "reason": "PLANT_NOT_BINDABLE"}
]}}
Real import, same request without dryRun (illustrative):
{"type": "import_devices_result", "requestId": "im-2", "ok": true, "result": {
"dryRun": false, "ok": 1, "failed": 0, "results": [
{"row": 1, "loggerId": "y25319070301", "ok": true,
"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f",
"plantId": "01JPLANT00000000000000000A",
"device": {"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f", "type": "inverter", "...": "as get_device_details"},
"favourite": true}
]}}
| Row field | Type | Notes |
|---|---|---|
row | integer | Position in rows, from 1 |
loggerId | string | The canonical logger id |
ok | boolean | This row succeeded |
deviceKey | string | Real import, registered rows |
plantId | string | New. Real import, registered rows |
device | object | New. Real import, registered rows: the get_device_details result. Left out if it could not be read back, or the request ran out of time |
favourite | boolean | New. true when the device is now your favourite; left out when not |
code, error, reason | string | Failed rows. reason as in the register table above, plus PLANT_NOT_BINDABLE (archived plant, or none you may bind into) |
inverter, plantInverters | object, array | Failed rows with a PARALLEL_* reason |
warnings | string[] | Dry run: NOT_IN_FACTORY_RECORDS, ALREADY_REGISTERED. Real import: FAVOURITES_FULL |
What the app does with the real reply:
- Show a summary ("8 imported, 2 failed") from
okandfailed, and list the failed rows with theirreason. - Each row with
ok: trueopens from its owndevice. Ifdeviceis missing, open it withget_device_detailsanddeviceKey. - Open the plant with the row's
plantId(rows can go into different plants). - A row whose
warningscontainsFAVOURITES_FULLwas imported but not starred. Show the notice once for the whole import, not once per row.
Edge cases:
- Time limit 120 s. Rows run one at a time. Rows not reached in time
fail with
UNAVAILABLE("not attempted"); re-send only those. - Never resend a successful row. Rows are not idempotent: re-registering the same logger fails with a conflict.
- Duplicates in the file: the second occurrence of a logger id or
inverter serial fails with
INVALID_REQUEST. - Not done in a dry run: the dry run never stars anything and never
returns
device. - Who may import: a ticket grant with devices
MANAGE, otherwise the whole request isFORBIDDEN.
Task 3: Look up a device by its serial
Two ways to look up by serial. For a platform Super Admin or Administrator, both star the device they find.
3a. check_serial (add-device screen)
Before registering: is the serial factory-made, and is it in use?
{"type": "check_serial", "requestId": "cs-1", "serial": "AT5K2400123"}
{"type": "check_serial_result", "requestId": "cs-1", "ok": true, "result": {
"serial": "AT5K2400123", "known": true,
"units": [{"kind": "inverter", "serial": "AT5K2400123", "model": null, "manufacturedOn": "2025-06-11", "batch": "B-0611"}],
"registered": true, "deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f", "registeredAs": "inverter",
"favourite": true
}}
| Field | Notes |
|---|---|
serial | 1–64 characters of letters, digits, -, _, .; a logger id or an inverter serial |
registered | A device in service uses the serial |
deviceKey | Only when you can see that device. Then "Open device" can use it |
favourite | New. Present (true) only when the device is now your favourite. That happens only together with deviceKey, and only for a platform Super Admin or Administrator |
warnings | New, optional. ["FAVOURITES_FULL"] |
Needs a ticket grant with devices MANAGE (FORBIDDEN otherwise).
3b. search_devices with the whole serial
The search box sends search_devices as the user types (2–64 characters,
a prefix of a logger id or inverter serial, limit default 20, max
50). A prefix never stars anything. When q is a device's whole logger
id or inverter serial (case does not matter), that device is starred for a
platform Super Admin or Administrator, and its row comes back with
"favourite": true.
{"type": "search_devices", "requestId": "s-1", "q": "AT5K2400123", "limit": 5}
{"type": "search_devices_result", "requestId": "s-1", "ok": true, "result": {
"devices": [{"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f", "loggerId": "m2506a0012",
"inverterSn": "AT5K2400123", "plantId": "01JPLANT00000000000000000A",
"plantName": "Model Town rooftop", "favourite": true, "...": "..."}]
}}
warnings: ["FAVOURITES_FULL"] is added at the top of result at the cap.
Debounce the search (about 250–300 ms) and cancel stale requests: the connection allows only 4 console requests at once, and each keystroke that completes a serial stars a device.
Task 4: Opening the plant
Every reply in Task 2 carries plantId. The plant itself lives in the
HTTP server, not here:
GET /v1/plants/{plantId}
Authorization: Bearer <token>
See the HTTP docs:
Plant detail, GET /v1/plants/{plantId}.
The app's own (mobile) form needs no X-Org-Id. A platform Super Admin or
Administrator can read any plant this way. Show the device screen from the
TCP reply at once, and load the plant alongside it: do not wait for one
before starting the other.
If the HTTP call fails, still show the device. Show the plant section as unavailable with a retry.
Task 5: Devices list with pinned favourites
How the list is built
The first page of get_inventory (all devices) or get_devices_page
(one plant, or "all") comes in two blocks:
- Pinned favourites: your 15 most recently starred devices that you
can still reach, each
"favourite": true, newest first. They ignore the filters and sort. If you have more, the page carriesfavouritesNextCursor. - The list itself: filtered, sorted and paged as before (
limit, default 50, max 200), with its ownnextCursor. It never contains a favourite.
So the first page can hold up to limit + 15 rows. Pages after the first
(sent with cursor) carry no pinned favourites and no
favouritesNextCursor.
{"type": "get_devices_page", "requestId": "p-1", "plantId": "all", "limit": 50}
{"type": "get_devices_page_result", "requestId": "p-1", "ok": true, "result": {
"devices": [
{"deviceKey": "aaaa…", "favourite": true, "...": "pinned 1 of 15"},
{"deviceKey": "bbbb…", "favourite": true, "...": "pinned 15 of 15"},
{"deviceKey": "cccc…", "favourite": false, "...": "list row 1"}
],
"favouritesNextCursor": "eyJ0IjoiMjAyNi0xMS0yNFQw…",
"nextCursor": "eyJzIjoicmVnaXN0ZXJlZEF0Ii…",
"counts": {"total": 1250, "...": "..."}
}}
| Field | Notes |
|---|---|
devices | Pinned favourites first (favourite: true), then list rows. Split them by position: the leading run of favourite: true rows is the pinned block |
favouritesNextCursor | New. First page only, present only when there are more favourites. Pass it to list_favourites |
nextCursor | The list's next page, as before. Absent on the last page |
counts | First page only. Counts the devices matching the filters, favourites included, so it can be more than the list rows you will page through |
Single plant: get_devices_page with a plant id pins only your
favourites in that plant, and its favouritesNextCursor continues
only that plant's favourites, in the same row shape (lastReadings,
lifetimePvGenerationKwh, pendingLoggerId). get_inventory and
plantId: "all" pin all of them.
Loading more favourites: list_favourites
{"type": "list_favourites", "requestId": "f-2", "cursor": "eyJ0IjoiMjAyNi0xMS0yNFQw…"}
{"type": "list_favourites_result", "requestId": "f-2", "ok": true, "result": {
"devices": [{"deviceKey": "dddd…", "favourite": true, "...": "..."}],
"nextCursor": "eyJ0IjoiMjAyNi0xMS0yM1Qx…"
}}
| Field | Type | Notes |
|---|---|---|
cursor | string | favouritesNextCursor from a list, or nextCursor from the previous list_favourites |
limit | integer | Leave out. Default 15 without a cursor, 10 with one. If sent, used as is (1–200) |
devices | array | Device rows, favourite: true, most recently starred first |
nextCursor | string or null | null after the last favourite. It is always present |
No duplicates. The list block never has a favourite, and each favourites load continues after the last one given. So no device appears twice across the pinned block, the favourites loads and the list pages. The cursor holds a position (when the last one was starred, and its id), so starring more devices while scrolling neither skips nor repeats any. New favourites appear on the next refresh.
A favourites cursor is not a list cursor. Send favouritesNextCursor
and list_favourites' nextCursor only to list_favourites, and the
list's nextCursor only to the same list message with the same filters.
Flutter-side state (sketch)
Pseudocode, not app code:
state DevicesListState:
pinned: List<DeviceRow> // favourites block
favCursor: String? // favouritesNextCursor, then list_favourites.nextCursor
rows: List<DeviceRow> // the list's own rows
listCursor: String? // the list's nextCursor
counts: Counts?
loadingFav, loadingList: bool
refresh(filters): // first open, filter change, pull-to-refresh
reset everything (both cursors to null, both lists empty)
r = send get_devices_page{plantId, filters, limit: 50} // or get_inventory
pinned = leading rows of r.devices with favourite == true
rows = the remaining rows
favCursor = r.favouritesNextCursor // may be absent → null
listCursor = r.nextCursor // may be absent → null
counts = r.counts
loadMoreFavourites(): // "Show more favourites" button under the pinned block
if favCursor == null or loadingFav: return
r = send list_favourites{cursor: favCursor} // no limit → 10
pinned += r.devices
favCursor = r.nextCursor // null → hide the button
loadMoreList(): // infinite scroll at the bottom
if listCursor == null or loadingList: return
r = send get_devices_page{plantId, filters, cursor: listCursor, limit: 50}
rows += r.devices // no pinned rows on later pages
listCursor = r.nextCursor // absent → end of list
on unstar(device) in pinned: // after remove_favourite succeeds
remove it from pinned // it reappears in rows only after refresh()
on star(device) in rows: // after add_favourite succeeds
mark it starred in place // it moves to pinned on the next refresh()
Rules:
- Pull-to-refresh and any filter or sort change reset both cursors and reload page 1. Never mix a cursor with other filters.
- Keep the two loads independent. Loading more favourites never
touches
listCursor, and the reverse. - De-duplicate by
deviceKeyon the client anyway when you change a star locally between refreshes. The server guarantees no duplicates only for what it sends from one consistent state. - Favourites you no longer reach are skipped by the server before it
counts the page, so a load returns fewer than 10 rows only at the end
(
nextCursoris thennull). Still loop onnextCursor, not on the row count.
The Favourites screen (if the app has one) is just list_favourites
with no cursor (15), then its nextCursor (10 each), until null.
Task 6: Star and unstar by hand
{"type": "add_favourite", "requestId": "f-1", "deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f"}
{"type": "add_favourite_result", "requestId": "f-1", "ok": true,
"result": {"deviceKey": "3f2c8a9e-5b1d-4c7a-9e2f-1a2b3c4d5e6f", "changed": true}}
remove_favourite takes the same field and answers the same way.
| Rule | Detail |
|---|---|
| Idempotent | changed: false when it already was (or was not) a favourite. Starring an existing favourite does not move it to the top |
| Cap | 200 favourites per user. add_favourite beyond that is CONFLICT. Automatic stars never fail: they skip and warn (FAVOURITES_FULL) |
| Access | add_favourite needs devices EDIT on the device (FORBIDDEN / NOT_FOUND otherwise). remove_favourite works even for a device you no longer reach |
| Lifetime | A favourite of a device that leaves your access is kept and shown again if access returns. Deleting the device removes it |
At the cap, offer the user the favourites list to remove some, rather than retrying.
Task 7: list_favourites contract changes
list_favourites changed on 2026-11-24. If the app already calls it:
| What | Before | Now |
|---|---|---|
| Default page size, no cursor | 50 | 15 |
| Default page size, with a cursor | 50 | 10 |
nextCursor at the end | Left out | Always present, null at the end. Test for null, not for a missing key, and accept both while older servers are around |
| Order | Most recently starred first | Same |
inverterSn of a deactivated device whose inverter was released | null | The released serial, as on get_inventory rows |
| Row shape | Device row | Same device row; a cursor from get_devices_page for one plant also gives lastReadings, lifetimePvGenerationKwh, pendingLoggerId |
| Old cursors | Still accepted |
An explicit limit keeps working exactly as before (1–200).
Other messages changed only additively: new fields on replies, nothing
removed or renamed. An older server simply leaves the new fields out, so
the app should treat device, favourite, warnings and
favouritesNextCursor as optional.
Task 8: QA checklist and what is not done yet
Test checklist
Sign in as a platform Super Admin, a platform Administrator, a Business Admin and an installer, and check:
- Register one device: the device screen opens from the reply, with no extra loading step, and the plant loads from the HTTP server.
- Super Admin / Administrator: the new device is starred, and appears at the top of the devices list after a refresh.
- Business Admin / installer: registering works, the device is not
starred (
favourite: false). - Batch import with a mix of good and bad rows: dry run lists the problems and registers nothing; the real run shows the summary, each good row opens, bad rows show their reason.
- Import rows into two different plants: each row opens its own plant.
-
check_serialand a whole-serial search star the device for a Super Admin; typing a prefix stars nothing. - With 200 favourites: registration and import still succeed and show
the "favourites full" notice once;
add_favouriteshows the cap error. - Devices list with more than 15 favourites: 15 pinned, "show more" loads 10 at a time, the button disappears at the end, and no device shows twice anywhere in the list.
- Apply a filter (e.g. offline only): pinned favourites still show, the list below is filtered.
- One plant's device page pins only that plant's favourites.
- Pull-to-refresh resets both "show more favourites" and the infinite scroll.
- Unstar a pinned device: it leaves the pinned block; after refresh it is in the normal list.
-
device: nullpath (simulate by ignoringdevice): the screen opens viaget_device_detailsand the registration is not retried. - A user without devices
MANAGE: import andcheck_serialare hidden or answerFORBIDDEN.
What is not done yet
- Not deployed and not committed. The code is in the cse_tcp_be working
tree only. Until it is deployed to dev, the dev server answers with the
old shapes (no
device,favourite,warnings,favouritesNextCursor;list_favouritesdefaults to 50). - Database integration tests not run. The tests for import with
details, auto-favourites, pinned favourites and lazy loading are
written but need a test database. Unit tests,
go vetand the build pass. - No live capture. Every example on this page is illustrative.
- Dev only. Staging and production are not deployed.
- Open question for the owner: whether a Business's own Admin or Super Admin should also get automatic favourites. Today only the platform Super Admin and Administrator do.