Logger and inverter binding rules (QA reference)
A checklist of every rule that decides which logger is bound to which inverter, written for QA test planning. It describes what the backend currently implements. For the request and reply shapes see Device registration and Updating a device.
The rules are enforced in cse_tcp_be:
server/internal/storage/postgres/identity.go (registration and connect),
logger_move.go (moving a logger between devices),
device_update.go (logger change), and server/internal/server/server.go
(what the TCP server does with each connect outcome).
Basics
- A logger can be on only one live device at a time. An inverter serial can belong to only one live device. Deleted (revoked) devices are not live.
- A device is the inverter. Its
deviceKeyand its history stay the same when its logger changes. - Logger IDs are compared without regard to case. The app's QR code gives lowercase and the hardware sends uppercase, so both match.
- A sighting is the inverter serial the server last read from a logger whose connection was not accepted. Registration uses a sighting only if it is newer than the device's last accepted connection.
A. Registering a device in the app (register)
The message type is register (see the
message reference); there is no
register_device message.
| # | Situation | Result | Error code / message |
|---|---|---|---|
| A1 | New logger, never connected, no serial sent | Accepted. Device created as pending_connection ("waiting for device") | — |
| A2 | New logger. Its sighting shows an inverter that no device owns | Accepted as a new device | — |
| A3 | Same user registers the same logger again, in the same plant (a retry) | Accepted, same deviceKey returned. An active device stays active | — |
| A4 | Logger belongs to another user's device (including one still waiting to connect), and the caller may not add it (A19) | Refused | NOT_AUTHORIZED: "sorry, this device is not authorized for your account" |
| A5 | Same user, logger is already their device in a different plant, and the logger has not moved | Refused. Exception: if that device never connected and the logger's sighting shows an inverter that is already the user's device in the plant being registered into, A11 applies instead (the empty claim is removed) | DEVICE_IN_ANOTHER_PLANT, with existingPlantId and existingDeviceKey |
| A6 | Same user, logger already has an inverter, and the app sends a different typed serial | Refused | LOGGER_ALREADY_BOUND |
| A7 | Logger is the device of a deleted (revoked) device | Refused for everyone, including the previous owner | DEVICE_REVOKED: "contact support to have it restored" |
| A8 | Logger is another device's pending new logger (an update_device swap less than 7 days old) | Refused | LOGGER_ALREADY_BOUND |
| A9 | Inverter (typed serial or sighting) already belongs to another user's device | Refused, naming nothing of theirs | NOT_AUTHORIZED: "sorry, this device is not authorized for your account" |
| A10 | Logger moved: same user's logger was on inverter X and its sighting now shows inverter Y, which nobody owns | New device created for Y. The old device is deactivated: it keeps its history, has no logger, its open alerts are closed and it gets the info alert device.LOGGER_REMOVED. If the old device never connected, it is deleted instead | — |
| A11 | Sighting shows the logger is on an inverter that is already this user's device, in the same plant | Logger is fitted to that existing device, and its existing deviceKey is returned. The device goes to pending_connection until the logger connects. The device the logger left is deactivated (as in A10). Info alert device.LOGGER_REPLACED | — |
| A12 | Same as A11, but that device is in a different plant | Refused | DEVICE_IN_ANOTHER_PLANT, with existingPlantId and existingDeviceKey |
| A13 | Serial was typed by the user rather than sighted | A logger is never taken off a device on a typed serial alone. Another user's inverter gives A9; the user's own device in another plant gives A12. In the same plant, a device that still has a logger is refused; a device with no logger (deactivated) gets this logger fitted, and the pairing is checked when the logger connects (a different inverter is refused as logger_moved) | DEVICE_ALREADY_REGISTERED (same plant, device still has a logger) |
| A14 | Two users register the same new logger at the same moment | The first one wins | Second user gets NOT_AUTHORIZED |
| A15 | Logger is still connected when it is registered | Server closes the connection, the DTU reconnects within seconds and the data starts flowing | — |
| A16 | Logger belongs to a deleted device whose hardware reset was still waiting | Registering cancels the pending reset | — |
| A17 | Inverter is held by a deactivated device with no logger (its logger was unbound) that the caller may add (A19) | It is the caller's device: rule A11 fits the logger back to it, history kept. The same holds when that device had its inverter released (D6): it takes its serial back from released_inverter_sn instead of the inverter becoming a second device (migration 0159) | — |
| A18 | Inverter is held by a deactivated device with no logger that the caller may not add (another account's) | Sighting: the inverter is released. The old device keeps its id and history, with the serial moved to released_inverter_sn and an Activity Trail entry inverter_released; the logger is registered as a new device with no history. Typed serial only: refused, because a label is not proof | Typed serial: DEVICE_ALREADY_REGISTERED: "this inverter serial is still held by a device whose logger was removed; add the logger without entering the inverter serial…" |
| A19 | Device already exists and the caller is not its user owner, but may add it: devices MANAGE on it through a grant, an administrator of its Business (ticket oa), or, for a device with no user owner, a member of the Business it belongs to (the ticket's org is the operator of its plant, or its owner_org_id when it is in no plant). This is a device an administrator transferred without naming a user, unbound from its plant, or took the logger off | Treated as the caller's own device: A3, A5, A11, A12 apply. A device with no user owner takes the registering user as owner; one that has a user owner keeps it. Without a ticket, only user ownership counts | — |
| A20 | Logger's device is in no plant, has no user owner, is held by a Business's org, and the caller may not add it (another Business's unassigned stock, e.g. after its logger was unbound). A free device (no plant, no org, no user owner: its plant was deleted or it was removed from its plant) is not refused: any user or Business may add it, history and serial kept | Refused | LOGGER_ALREADY_BOUND: "this device is held as unassigned stock; ask an administrator of the Business that holds it to assign it to your plant" |
| A21 | Device the logger resolves to (A3, A11, A19) is in no plant | It joins the plant being registered into. Its open alerts move with it, and it gets the info alert device.MOVED_IN ("Device added to this plant"). Exception: a device that belongs to a Business joins only a plant of that Business. Another Business's plant, or a plant the server has no record of, is refused. A device of no Business may join any plant | — / NOT_AUTHORIZED: "this device belongs to another Business and cannot be added to this plant" (console: FORBIDDEN OWN_PLANTS_ONLY) |
| A22 | The plant is archived (or being deleted) on the HTTP Server, and the logger is not already a device in it | Refused; the same rule applies to the console's bind_device, transfers and imports, and to update_device plant moves | PLANT_NOT_BINDABLE |
| A23 | A brand-new device (no existing row) registered into a plant | It belongs to the Business that operates the plant, whoever registers it. With no record of the plant yet, it takes the registering ticket's org. An existing device never has its Business changed by registering | — |
B. When the device connects (TCP server)
| # | Situation | Outcome | Data saved / shown in app? |
|---|---|---|---|
| B1 | Logger matches its device and the inverter serial matches | bound | Yes |
| B2 | Device was pending_connection with no serial yet | claimed_pending: the serial is saved as verified and the status becomes active | Yes |
| B3 | Serial could not be read (some models have no serial register) | unverified | Yes, the pairing is just not checked |
| B4 | Logger is bound to inverter X but is now plugged into Y | logger_moved, refused. Sighting recorded. Fix: register it again from the app (A10/A11) | No |
| B5 | Inverter already belongs to a different device | inverter_taken, refused. Sighting recorded | No |
| B6 | Logger was registered as a new device (A1) but turns out to be on an inverter the same user already has, in the same plant (either plant not set also counts). A deactivated device with no user owner that belongs to the Business the registration was made under also counts, and takes the registering user as owner | The empty new device is removed and the logger is fitted to the existing device, with history kept. An existing device in no plant joins the empty device's plant (device.MOVED_IN), unless it belongs to a Business that does not operate that plant: then it stays in no plant, served as its Business's stock | Yes |
| B7 | Same as B6, but a different plant | inverter_taken, refused. Registering the logger again tells the user where the device is (A5/A12); registering from that plant fits it there | No |
| B9 | Logger registered with no serial yet (A1) reports an inverter held by another user's deactivated device with no logger (not the registrant's own, and not their Business's ownerless stock, which give B6 or B7) | The old device's inverter is released (as in A18) and bound to this device: claimed_pending, served | Yes |
| B10 | Same as B7, but a different owner, and the device still has a logger | inverter_taken, refused | No |
| B11 | Logger plugged back: the logger is the user's device d2 and reports the inverter of the same user's device d1 that has no logger (deactivated, e.g. by A10 when the logger moved from d1 to d2) | No registration needed. The logger is fitted back to d1 and served at once (logger_replaced): d1 is active in its own plant with its history continuing, info alert device.LOGGER_REPLACED. d2 is deactivated in its plant, keeping its serial and history (device.LOGGER_REMOVED). Plugged into d2's inverter again, it swaps back the same way. Never applies to a d1 that still has a logger, or to another user's device: those stay B5. The plants' combined views pick up the change within a minute | Yes |
| B8 | Logger was never registered, or belongs to a deleted (revoked) device | unknown. Sighting recorded. If the device was deleted with a hardware reset pending, the reset (factory restore) is sent now | No |
When a connection is refused or unknown, the connection itself stays open, but its data is not saved and does not appear in the app.
An inverter_taken refusal (B5, B7, B10) is logged by the TCP server as
REFUSING this connection: this inverter is already bound to a different logger. On that line, device_id is the refused logger's own device
(often the one just registered, still pending_connection), not the device
holding the inverter. The holder is named separately:
| Field | Meaning |
|---|---|
held_by_device_id | The device that holds the inverter. This is the one to act on |
held_by_logger_id | Its logger, or none when it has no logger fitted |
held_by_status | Its status (active, deactivated, …) |
The three fields are left out if the holder could not be looked up, or was
removed in the moment between the refusal and the lookup. Freeing the
inverter means acting on held_by_device_id: unbind its logger from the web
console (D), or revoke or delete it. Deleting the refused logger's own
device changes nothing. The refused logger is served on its next connection
once the inverter is free.
C. Changing a device's logger (update_device → loggerId)
| # | Situation | Result | Code |
|---|---|---|---|
| C1 | New logger given for a device whose serial has been verified by the hardware | Swap is pending for up to 7 days. The old logger keeps working | — |
| C2 | Pending new logger connects and reports that device's serial | Swap completes: same deviceKey and history, the old logger stops being recognised. Info alert device.LOGGER_REPLACED | — |
| C3 | Pending new logger reports a different serial, or none can be read | Connection refused (logger_swap_refused). The swap stays pending | — |
| C4 | No connection within 7 days | Request expires and the logger is no longer reserved | — |
| C5 | Request names the device's current logger | unchanged. If a swap was pending, it is cancelled | — |
| C6 | Request repeats the same pending logger | Treated as a retry; stays pending | — |
| C7 | Device's serial has never been read from the hardware (never connected, typed serial only, or model has no serial register) | Refused | INVERTER_UNKNOWN |
| C8 | New logger is on another device (deleted devices count) or is pending on another device | Refused | LOGGER_IN_USE |
| C9 | Device doesn't exist or isn't this user's | Refused | DEVICE_NOT_FOUND |
| C10 | Device is deleted (revoked) | Refused | DEVICE_REVOKED |
| C11 | Device is no longer in the plant the app sent | Refused | STALE_DEVICE |
D. Unbinding a logger from the web console (unbind_logger)
Platform Admin / Super Admin only. No hardware evidence needed. See
unbind_logger.
| # | Situation | Result | Code |
|---|---|---|---|
| D1 | Device in service (pending_connection / active / inactive) | Logger removed, device deactivated, open alerts closed, live session closed, device moved out of its plant to its Business's stock | — |
| D2 | Device deactivated or revoked | Logger (and any pending swap) removed; status unchanged; moved out of its plant to its Business's stock | — |
| D3 | Device has no logger and no pending swap | changed: false | — |
| D4 | Caller is not a platform Admin / Super Admin | Refused | FORBIDDEN |
| D5 | Freed logger connects again | Unregistered logger, with its old sighting deleted. Registering it on the same inverter fits it back to the same device for anyone who may add it (A17, A19), and the device joins the plant registered into (A21); for anyone else the inverter is released and a new device created (A18, B9). On another inverter it is a new logger (A2) | — |
| D6 | releaseInverter: true | The inverter is freed as well: registering it again by another user creates a new device; the old device keeps its history. Its own owner (or Business, for stock) registering a logger on it again gets the old device back with its serial restored, never a second device (migration 0159). Works on a device whose serial the hardware has verified (migration 0130; before it, the database refused this) | — |
Things to look out for while testing
- In A10/A11, whether the logger counts as "moved" depends on a recent sighting. The logger has to have tried to connect from the new inverter before it is registered there. Otherwise registration falls back to A1, and the problem is only caught at connect time (B6 or B7).
- A revoked logger is refused at registration (A7) but treated as plain "unknown" at connect time (B8).