feat: add custom_data attribute to payload-related dataclasses #434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
OCPP-2.0.1_part2_specification_edition2
states:With some more details, provided in
OCPP-2.0.1_part4_ocpp-j-specification
:OCPP 2.0.1 specific
OCPP 1.6, for its part, does define the same concept of enabling the exchange of custom information between a CS and a CSMS, but through dedicated messages: please refer to "4.3. Data Transfer" in ocpp-1.6 edition 2.
Why not a Payload dataclass from which other payload dataclasses could inherit
I was thinking to just create a
Payload
dataclass, which all OCPP payloads (inocpp.v201.call.py
andocpp.v201.call_result.py
) could inherit from:Example:
But the thing is, TMH currently uses Python>=3.7. And before Python 3.10, inheritance with dataclasses is quite messy: with the approach proposed above, as
custom_data
is a default argument, payload classes inheriting fromPayload
would require having all of their attributes defining default values, which we obviously don't want.So, instead, I have resignated myself to modify all OCPP payloads directly to define a
custom_data: Optional[Dict[str, Any]] = None
attribute for each payload class inocpp.v201.call.py
andocpp.v201.call_result.py
.