Skip to content

Fixed OCPP connector failing to load on ocpp 2.x - #2161

Open
cafe-jun wants to merge 1 commit into
thingsboard:masterfrom
cafe-jun:fix/ocpp-library-api-rename
Open

Fixed OCPP connector failing to load on ocpp 2.x#2161
cafe-jun wants to merge 1 commit into
thingsboard:masterfrom
cafe-jun:fix/ocpp-library-api-rename

Conversation

@cafe-jun

@cafe-jun cafe-jun commented Aug 24, 2026

Copy link
Copy Markdown

Closes #1908

Problem

The OCPP connector cannot be imported at all on current versions of the ocpp library:

File "/thingsboard_gateway/connectors/ocpp/charge_point.py", line 64, in ChargePoint
    @on(Action.BootNotification)
AttributeError: type object 'Action' has no attribute 'BootNotification'.
Did you mean: 'boot_notification'?

ocpp 1.0 deprecated two things and 2.0 removed them:

  • the PascalCase Action enum members, in favour of snake_case
  • the Payload suffix on call / call_result classes

The 1.0 source says so explicitly:

Action enum contains deprecated members and will be removed in the next major release, please use snake case members.

requirements-full.txt lists ocpp unpinned, so any fresh install resolves to 2.x and the connector is dead on arrival. TBModuleLoader reports the import failure and no OCPP device can connect.

Change

Renamed 16 references across two files to the current API:

before after
Action.BootNotification Action.boot_notification
call_result.BootNotificationPayload call_result.BootNotification
call.DataTransferPayload call.DataTransfer

…and the same for Authorize, Heartbeat, MeterValues, DataTransfer.

This does not drop ocpp 1.x support

Both spellings exist in 1.0, so the new names resolve there too. No version pin is needed and no existing install breaks.

The enum values are also identical, so nothing changes at runtime:

>>> Action.meter_values.value        # ocpp 1.0.0 and 2.1.0
'MeterValues'

That matters because Action.meter_values is passed through as messageType to the uplink converter — the converter still receives the same string it did before.

Verification

Imported charge_point and ocpp_connector against three library versions:

ocpp before after
1.0.0 imports imports
2.0.0 AttributeError imports
2.1.0 AttributeError imports

So the change strictly widens the supported range rather than shifting it.

Notes

  • No tests added: there is no OCPP coverage under tests/ today. Happy to add an import smoke test if you would like one in this PR.
  • I did not pin ocpp in requirements-full.txt, since the connector now works on both major versions. Let me know if you would rather have a lower bound recorded there anyway.
  • Only the names the connector actually uses were touched. I did not sweep the rest of the OCPP surface for other deprecations.

The ocpp library deprecated the PascalCase Action enum members and the
*Payload suffix on call/call_result classes in 1.0, and removed them in
2.0. The connector still used the old names, so importing it raises
AttributeError and the OCPP connector cannot be loaded at all. The
library is unpinned in requirements-full.txt, so every new install hits
this.

Renamed to the current API: Action.BootNotification ->
Action.boot_notification, call_result.BootNotificationPayload ->
call_result.BootNotification, and so on.

Both spellings exist in ocpp 1.0, so this keeps working there — the
enum values are identical (Action.meter_values.value == "MeterValues"),
so the messageType passed to the uplink converter is unchanged.

Verified the connector imports on ocpp 1.0.0, 2.0.0 and 2.1.0, where
before it only imported on 1.0.0.

Closes thingsboard#1908
@cafe-jun
cafe-jun force-pushed the fix/ocpp-library-api-rename branch from 5563fde to 664f146 Compare August 24, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OCPP connector @on(Action.BootNotification) error on loading

1 participant