Skip to main content

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:


What changes for the user​

ScreenTodayAfter this change
Add device / batch importThe reply gives only a device id; the app must fetch the deviceThe 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 serialShows the deviceSame, and for an Admin/Super Admin the device is starred automatically
Devices listFavourites mixed in with the restFavourites pinned at the top: the 15 most recent, then "load more" 10 at a time, then the normal list
Favourites screen50 per page15 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.

CallerImport / registerAuto-favouriteFavourites 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)YesYes
Platform Administrator (ticket claim pa)SameYesYes
Other roles with a devices MANAGE grant (installer, operator, a Business Admin)Yes, into plants where they hold devices MANAGENoYes
Anyone else (e.g. a plain owner with no grant)No: FORBIDDENNoYes (their own manual favourites)
  • MANAGE comes from a ticket grant. Owning devices is not enough for import_devices or check_serial. register_device_web needs devices MANAGE on 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 oa claim) 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}
FieldTypeRequiredNotes
loggerIdstringyesLetters, digits, -, _, .; stored lower case
inverterSnstringnoStored upper case. Leave out to have it read from the hardware
plantIdstringyesUpper-cased by the server
ownerSubstringnoA user id (UUID). Used only when the server does not know the plant's owner yet. Default: you
draftIdstringnoA registration draft to delete on success
parallelbooleannoDefault 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 fieldTypeNotes
deviceKeystring (UUID)The device id. Unchanged from before
plantIdstringThe plant. Unchanged from before
deviceobject or nullNew. 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
favouritebooleanNew. The device is now one of your favourites
warningsstring[]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:

  1. Open the device screen with result.device. Do not send get_device_details again.
  2. If result.device is null, the device is registered. Open the device screen by sending get_device_details with result.deviceKey. Do not retry the registration: a retry fails with DEVICE_ALREADY_REGISTERED or LOGGER_ALREADY_BOUND.
  3. Load the plant with result.plantId (Task 4).
  4. Mark the device starred if result.favourite is true. If warnings contains FAVOURITES_FULL, show a one-line notice ("Not added to favourites: you already have 200. Remove one to make room."). Registration still succeeded.
  5. favourite: false with 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:

codedetails.reasonShow
FORBIDDEN(none)You need devices MANAGE on this plant
FORBIDDENNOT_AUTHORIZEDThe hardware is registered to another account
FORBIDDENOWN_PLANTS_ONLYThe device belongs to another Business; transfer it instead
CONFLICTDEVICE_IN_ANOTHER_PLANTThe inverter is in another plant (existingPlantId, existingDeviceKey when you may see them)
CONFLICTLOGGER_ALREADY_BOUNDThe logger is on another device
CONFLICTDEVICE_REVOKEDThe device was taken out of service
CONFLICTDEVICE_ALREADY_REGISTEREDThe inverter is registered with another logger
CONFLICTPARALLEL_*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"}
]}
FieldTypeRequiredNotes
rowsarrayyes1–100 rows. Split a larger file
rows[].loggerId, inverterSn, plantId, ownerSub, parallelAs for register_device_web
dryRunbooleannotrue 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 fieldTypeNotes
rowintegerPosition in rows, from 1
loggerIdstringThe canonical logger id
okbooleanThis row succeeded
deviceKeystringReal import, registered rows
plantIdstringNew. Real import, registered rows
deviceobjectNew. 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
favouritebooleanNew. true when the device is now your favourite; left out when not
code, error, reasonstringFailed rows. reason as in the register table above, plus PLANT_NOT_BINDABLE (archived plant, or none you may bind into)
inverter, plantInvertersobject, arrayFailed rows with a PARALLEL_* reason
warningsstring[]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 ok and failed, and list the failed rows with their reason.
  • Each row with ok: true opens from its own device. If device is missing, open it with get_device_details and deviceKey.
  • Open the plant with the row's plantId (rows can go into different plants).
  • A row whose warnings contains FAVOURITES_FULL was 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 is FORBIDDEN.

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
}}
FieldNotes
serial1–64 characters of letters, digits, -, _, .; a logger id or an inverter serial
registeredA device in service uses the serial
deviceKeyOnly when you can see that device. Then "Open device" can use it
favouriteNew. 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
warningsNew, 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:

  1. 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 carries favouritesNextCursor.
  2. The list itself: filtered, sorted and paged as before (limit, default 50, max 200), with its own nextCursor. 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, "...": "..."}
}}
FieldNotes
devicesPinned favourites first (favourite: true), then list rows. Split them by position: the leading run of favourite: true rows is the pinned block
favouritesNextCursorNew. First page only, present only when there are more favourites. Pass it to list_favourites
nextCursorThe list's next page, as before. Absent on the last page
countsFirst 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…"
}}
FieldTypeNotes
cursorstringfavouritesNextCursor from a list, or nextCursor from the previous list_favourites
limitintegerLeave out. Default 15 without a cursor, 10 with one. If sent, used as is (1–200)
devicesarrayDevice rows, favourite: true, most recently starred first
nextCursorstring or nullnull 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 deviceKey on 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 (nextCursor is then null). Still loop on nextCursor, 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.

RuleDetail
Idempotentchanged: false when it already was (or was not) a favourite. Starring an existing favourite does not move it to the top
Cap200 favourites per user. add_favourite beyond that is CONFLICT. Automatic stars never fail: they skip and warn (FAVOURITES_FULL)
Accessadd_favourite needs devices EDIT on the device (FORBIDDEN / NOT_FOUND otherwise). remove_favourite works even for a device you no longer reach
LifetimeA 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:

WhatBeforeNow
Default page size, no cursor5015
Default page size, with a cursor5010
nextCursor at the endLeft outAlways present, null at the end. Test for null, not for a missing key, and accept both while older servers are around
OrderMost recently starred firstSame
inverterSn of a deactivated device whose inverter was releasednullThe released serial, as on get_inventory rows
Row shapeDevice rowSame device row; a cursor from get_devices_page for one plant also gives lastReadings, lifetimePvGenerationKwh, pendingLoggerId
Old cursorsStill 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_serial and 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_favourite shows 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: null path (simulate by ignoring device): the screen opens via get_device_details and the registration is not retried.
  • A user without devices MANAGE: import and check_serial are hidden or answer FORBIDDEN.

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_favourites defaults 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 vet and 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.