Skip to content

Solves a timing problem when the vehicle is plugged in and the RFID tag has not yet been recognized.#3229

Open
dawys wants to merge 3 commits intoopenWB:masterfrom
dawys:master
Open

Solves a timing problem when the vehicle is plugged in and the RFID tag has not yet been recognized.#3229
dawys wants to merge 3 commits intoopenWB:masterfrom
dawys:master

Conversation

@dawys
Copy link

@dawys dawys commented Mar 22, 2026

More information is available here:

https://forum.openwb.de/viewtopic.php?t=11971

dawys added 2 commits March 22, 2026 10:12
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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id into OCPP MeterValues calls (transfer_values) so meter data is tied to the correct transaction.
  • Gate StartTransaction so 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.

Comment on lines +705 to +710

# 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):

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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):

Copilot uses AI. Check for mistakes.
Comment on lines +705 to +710

# 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):

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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):

Copilot uses AI. Check for mistakes.
Comment on lines 702 to +716
# 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)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +706 to +708
# 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
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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 uses AI. Check for mistakes.
@dawys
Copy link
Author

dawys commented Mar 23, 2026

copilot suggestions gepushed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants