Solves a timing problem when the vehicle is plugged in and the RFID tag has not yet been recognized.#3229
Solves a timing problem when the vehicle is plugged in and the RFID tag has not yet been recognized.#3229dawys wants to merge 3 commits intoopenWB:masterfrom
Conversation
the transaction remains traceable even after the websocket performs a reconnect
… set check if the chargebox ID is set in the backend and if the rfid tag or the vehicle ID has been detected
There was a problem hiding this comment.
Pull request overview
This PR adjusts the OCPP flow to avoid starting/sending OCPP data too early (e.g., when a vehicle is plugged in but the RFID/vehicle ID is not yet available), and ensures MeterValues are associated with the active OCPP transaction.
Changes:
- Pass
transaction_idinto OCPPMeterValuescalls (transfer_values) so meter data is tied to the correct transaction. - Gate
StartTransactionso it is only triggered once a chargebox ID and an RFID/vehicle ID are present (to address the timing issue described in the PR title).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
packages/control/optional.py |
Updates OCPP meter value transfer call to include ocpp_transaction_id. |
packages/control/ocpp.py |
Extends transfer_values to include and forward transaction_id into call.MeterValues. |
packages/control/chargepoint/chargepoint.py |
Changes when start_transaction() is invoked, requiring chargebox ID and RFID/vehicle ID. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # only start OCPP transaction if chargebox ID is not none | ||
| if (self.data.config.ocpp_chargebox_id is not None): | ||
| # only start OCPP transaction if rfid tag or vehicle ID is set | ||
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): | ||
|
|
There was a problem hiding this comment.
In this block there are whitespace-only lines (after the if and before calling start_transaction). These add noise and can trigger formatting/lint issues; please remove the blank lines containing only spaces.
| # only start OCPP transaction if chargebox ID is not none | |
| if (self.data.config.ocpp_chargebox_id is not None): | |
| # only start OCPP transaction if rfid tag or vehicle ID is set | |
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): | |
| # only start OCPP transaction if chargebox ID is not none | |
| if (self.data.config.ocpp_chargebox_id is not None): | |
| # only start OCPP transaction if rfid tag or vehicle ID is set | |
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): |
|
|
||
| # only start OCPP transaction if chargebox ID is not none | ||
| if (self.data.config.ocpp_chargebox_id is not None): | ||
| # only start OCPP transaction if rfid tag or vehicle ID is set | ||
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): | ||
|
|
There was a problem hiding this comment.
The guard if (self.data.config.ocpp_chargebox_id is not None) still allows an empty string chargebox id, which will later be ignored by _process_call (it checks and chargebox_id). Consider checking truthiness (if self.data.config.ocpp_chargebox_id:) so you don’t attempt to start a transaction with an invalid/empty ID.
| # only start OCPP transaction if chargebox ID is not none | |
| if (self.data.config.ocpp_chargebox_id is not None): | |
| # only start OCPP transaction if rfid tag or vehicle ID is set | |
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): | |
| # only start OCPP transaction if chargebox ID is valid (non-empty) | |
| if self.data.config.ocpp_chargebox_id: | |
| # only start OCPP transaction if rfid tag or vehicle ID is set | |
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): |
| # OCPP Start Transaction nach Anstecken | ||
| if ((self.data.get.plug_state and self.data.set.plug_state_prev is False) or | ||
| (self.data.set.ocpp_transaction_id is None and self.data.get.charge_state)): | ||
| self.data.set.ocpp_transaction_id = data.data.optional_data.start_transaction( | ||
| self.data.config.ocpp_chargebox_id, | ||
| self.chargepoint_module.fault_state, | ||
| self.num, | ||
| self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id, | ||
| self.data.get.imported) | ||
|
|
||
| # only start OCPP transaction if chargebox ID is not none | ||
| if (self.data.config.ocpp_chargebox_id is not None): | ||
| # only start OCPP transaction if rfid tag or vehicle ID is set | ||
| if (self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id): | ||
|
|
||
| self.data.set.ocpp_transaction_id = data.data.optional_data.start_transaction( | ||
| self.data.config.ocpp_chargebox_id, | ||
| self.chargepoint_module.fault_state, | ||
| self.num, | ||
| self.data.set.rfid or self.data.get.rfid or self.data.get.vehicle_id, | ||
| self.data.get.imported) |
There was a problem hiding this comment.
This change makes start_transaction() conditional on an RFID tag / vehicle ID being present. That’s consistent with the intent, but it will break the current unit test expectation in packages/control/ocpp_test.py::test_start_transaction (it asserts a call with id_tag=None). Please update the test (e.g., set cp.data.get.vehicle_id or cp.data.set.rfid before cp.update(...)) to reflect the new behavior.
| # only start OCPP transaction if chargebox ID is not none | ||
| if (self.data.config.ocpp_chargebox_id is not None): | ||
| # only start OCPP transaction if rfid tag or vehicle ID is set |
There was a problem hiding this comment.
Surrounding comments in this file are predominantly German; the newly added comments here are English. For consistency/readability, consider translating these comments to match the rest of the file.
| # only start OCPP transaction if chargebox ID is not none | |
| if (self.data.config.ocpp_chargebox_id is not None): | |
| # only start OCPP transaction if rfid tag or vehicle ID is set | |
| # OCPP-Transaktion nur starten, wenn die Chargebox-ID nicht None ist | |
| if (self.data.config.ocpp_chargebox_id is not None): | |
| # OCPP-Transaktion nur starten, wenn ein RFID-Tag oder eine Fahrzeug-ID gesetzt ist |
|
copilot suggestions gepushed |
More information is available here:
https://forum.openwb.de/viewtopic.php?t=11971