Skip to main content

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 deviceKey and 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.

#SituationResultError code / message
A1New logger, never connected, no serial sentAccepted. Device created as pending_connection ("waiting for device")—
A2New logger. Its sighting shows an inverter that no device ownsAccepted as a new device—
A3Same user registers the same logger again, in the same plant (a retry)Accepted, same deviceKey returned. An active device stays active—
A4Logger belongs to another user's device (including one still waiting to connect), and the caller may not add it (A19)RefusedNOT_AUTHORIZED: "sorry, this device is not authorized for your account"
A5Same user, logger is already their device in a different plant, and the logger has not movedRefused. 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
A6Same user, logger already has an inverter, and the app sends a different typed serialRefusedLOGGER_ALREADY_BOUND
A7Logger is the device of a deleted (revoked) deviceRefused for everyone, including the previous ownerDEVICE_REVOKED: "contact support to have it restored"
A8Logger is another device's pending new logger (an update_device swap less than 7 days old)RefusedLOGGER_ALREADY_BOUND
A9Inverter (typed serial or sighting) already belongs to another user's deviceRefused, naming nothing of theirsNOT_AUTHORIZED: "sorry, this device is not authorized for your account"
A10Logger moved: same user's logger was on inverter X and its sighting now shows inverter Y, which nobody ownsNew 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—
A11Sighting shows the logger is on an inverter that is already this user's device, in the same plantLogger 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—
A12Same as A11, but that device is in a different plantRefusedDEVICE_IN_ANOTHER_PLANT, with existingPlantId and existingDeviceKey
A13Serial was typed by the user rather than sightedA 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)
A14Two users register the same new logger at the same momentThe first one winsSecond user gets NOT_AUTHORIZED
A15Logger is still connected when it is registeredServer closes the connection, the DTU reconnects within seconds and the data starts flowing—
A16Logger belongs to a deleted device whose hardware reset was still waitingRegistering cancels the pending reset—
A17Inverter 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)—
A18Inverter 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 proofTyped 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…"
A19Device 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 offTreated 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—
A20Logger'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 keptRefusedLOGGER_ALREADY_BOUND: "this device is held as unassigned stock; ask an administrator of the Business that holds it to assign it to your plant"
A21Device the logger resolves to (A3, A11, A19) is in no plantIt 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)
A22The plant is archived (or being deleted) on the HTTP Server, and the logger is not already a device in itRefused; the same rule applies to the console's bind_device, transfers and imports, and to update_device plant movesPLANT_NOT_BINDABLE
A23A brand-new device (no existing row) registered into a plantIt 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)​

#SituationOutcomeData saved / shown in app?
B1Logger matches its device and the inverter serial matchesboundYes
B2Device was pending_connection with no serial yetclaimed_pending: the serial is saved as verified and the status becomes activeYes
B3Serial could not be read (some models have no serial register)unverifiedYes, the pairing is just not checked
B4Logger is bound to inverter X but is now plugged into Ylogger_moved, refused. Sighting recorded. Fix: register it again from the app (A10/A11)No
B5Inverter already belongs to a different deviceinverter_taken, refused. Sighting recordedNo
B6Logger 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 ownerThe 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 stockYes
B7Same as B6, but a different plantinverter_taken, refused. Registering the logger again tells the user where the device is (A5/A12); registering from that plant fits it thereNo
B9Logger 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, servedYes
B10Same as B7, but a different owner, and the device still has a loggerinverter_taken, refusedNo
B11Logger 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 minuteYes
B8Logger was never registered, or belongs to a deleted (revoked) deviceunknown. Sighting recorded. If the device was deleted with a hardware reset pending, the reset (factory restore) is sent nowNo

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:

FieldMeaning
held_by_device_idThe device that holds the inverter. This is the one to act on
held_by_logger_idIts logger, or none when it has no logger fitted
held_by_statusIts 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)​

#SituationResultCode
C1New logger given for a device whose serial has been verified by the hardwareSwap is pending for up to 7 days. The old logger keeps working—
C2Pending new logger connects and reports that device's serialSwap completes: same deviceKey and history, the old logger stops being recognised. Info alert device.LOGGER_REPLACED—
C3Pending new logger reports a different serial, or none can be readConnection refused (logger_swap_refused). The swap stays pending—
C4No connection within 7 daysRequest expires and the logger is no longer reserved—
C5Request names the device's current loggerunchanged. If a swap was pending, it is cancelled—
C6Request repeats the same pending loggerTreated as a retry; stays pending—
C7Device's serial has never been read from the hardware (never connected, typed serial only, or model has no serial register)RefusedINVERTER_UNKNOWN
C8New logger is on another device (deleted devices count) or is pending on another deviceRefusedLOGGER_IN_USE
C9Device doesn't exist or isn't this user'sRefusedDEVICE_NOT_FOUND
C10Device is deleted (revoked)RefusedDEVICE_REVOKED
C11Device is no longer in the plant the app sentRefusedSTALE_DEVICE

D. Unbinding a logger from the web console (unbind_logger)​

Platform Admin / Super Admin only. No hardware evidence needed. See unbind_logger.

#SituationResultCode
D1Device 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—
D2Device deactivated or revokedLogger (and any pending swap) removed; status unchanged; moved out of its plant to its Business's stock—
D3Device has no logger and no pending swapchanged: false—
D4Caller is not a platform Admin / Super AdminRefusedFORBIDDEN
D5Freed logger connects againUnregistered 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)—
D6releaseInverter: trueThe 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).