-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.0.1 Action enums corrected #580
Conversation
(cherry picked from commit 30b69d3)
I'm unsure about this PR. Strictly speaking, this PR is correct. The PR corrects the casing the However, the change is backwards compatible and will break almost every application. What do you think of allowing the old notation (e.g. GetVariables) for now, but de deprecate them and remove them in a v2 version of ocpp. The deprecation warning should urge users to use the new notation (e.g get_variables). Python doesn't support deprecating enum members natively. But someone on StackOverflow came up with a clever fix using the |
I completely agree with you here, I will modify this PR and see if we incorporate the warning |
I have added the previous members back into the Action and in their current order, the result is as follows:
The problem we have here is that the name of the members changes and the value remains the same. Due to this the member is never missing, given the constraints of missing (see below). So after looking into this using missing we can only:
So to introduce a deprecation warning and also to remove these into the future becomes quite a conundrum ... however, the current change could be a logical step? |
Not sure if I follow you. I did some tests and figured out that Normal lookups, like I fixed that with this fix. from warnings import warn
from enum import StrEnum
class Action(StrEnum):
BootNotification = "BootNotification"
boot_notification = "BootNotification"
def __init__(self, *args, **kwargs):
if self.name == 'BootNotification':
warn("Action.BootNotification is deprecated and will be removed in the future. Please use Action.boot_notification.")
return super().__init__(*args, **kwargs)
print(Action.BootNotification)
print(Action.BootNotification.name)
print(Action.BootNotification.value)
print(Action.boot_notification)
print(Action.boot_notification.name)
print(Action.boot_notification.value)
print(Action['boot_notification'])
print(Action("BootNotification")) It prints:
|
I tried the above approach using
So I attempted to modify this some more and got this:
which results in:
Although this solves some of the problem, I couldn't get the new enum boot_notification to function correctly. I have identified that the order of members in the enums looks to determine this behaviour .... |
Good catch. I didn't realize the warning is show, even if you don't use any deprecated variants. I'm afraid we can't use the builtin warning to warn the users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that the enums of v16 are also incorrect. Can you update those as well?
@@ -2,6 +2,9 @@ | |||
- [#564](https://github.com/mobilityhouse/ocpp/issues/564) Add support For Python 3.11 and 3.12 | |||
- [#583](https://github.com/mobilityhouse/ocpp/issues/583) OCPP v1.6/v2.0.1 deprecate dataclasses from calls and call results with the suffix 'Payload' | |||
|
|||
## BREAKING ## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are not yet breaking, I suggest to change the title to "Deprecated".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Satisfied with commit acba23f
warn( | ||
"Action enum contains deprecated members and will be removed in " | ||
"the next major release, please use snake case members." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you apply the comment I made here to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Satisfied with commit 50e4a95
You can forget my earlier comment to include the v16 action. I see that the v16 action in #600 . |
…nto v2.0.1-Action-enums-corrected
- OCPP v1.6/v2.0.1 deprecate dataclasses from calls and call results with the suffix 'Payload' by @Jared-Newell-Mobility in #584 - In GA, validate project against Python 3.11 and 3.12. by @Jared-Newell-Mobility in #589 - drop support for python 3.7 by @Jared-Newell-Mobility in #585 - Update Code Owners by @Jared-Newell-Mobility in #588 - Revert "drop support for python 3.7" by @Jared-Newell-Mobility in #597 - OCPP 2.0.1 Wrong data type in CostUpdated total_cost by @Jared-Newell-Mobility in #596 - Update tests to use Call and CallResult without the suffix Payload by @Jared-Newell-Mobility in #595 - Fix camel_to_snake_case for "v2x" by @Jared-Newell-Mobility in #594 - Correct naming of members of v201.enums.AttributeType by @Jared-Newell-Mobility in #578 - Drop support for python 3.7 by @Jared-Newell-Mobility in #598 - Remove v1.6 deprecated enum variants by @Jared-Newell-Mobility in #575 - Typo in CostUpdated Action #435 by @Jared-Newell-Mobility in #491- - Remove support for ocpp 2.0 by @Jared-Newell-Mobility in #576 - v201.datatypes.ChargingNeedsType.request_energy_transfer is mistyped by @Jared-Newell-Mobility in #496 - v201.enums.StatusInfoReasonType.invaild_schedule by @Jared-Newell-Mobility in #521 - update to match Appendix 2. Standardized Units Of Measure by @Jared-Newell-Mobility in #512 - v16/schemas/StopTransaction.json missing "Hertz" #207 by @Jared-Newell-Mobility in #497 - Correct v2g serialisation/deserialisation by @Jared-Newell-Mobility in #606 - 2.0.1 dataclasses have a incorrect types that don't match carnality by @Jared-Newell-Mobility in #529 - Readthedocs_configuration_is_outdated by @Jared-Newell-Mobility in #608 - Readthedocs_configuration_is_outdated_config_update by @Jared-Newell-Mobility in #609 - The serialisation of soc to SoC should not occur in camel case if it is existing at the beginning of a field by @Jared-Newell-Mobility in #527 - Fix case conversion for soc in non "State of Charge" context by @Jared-Newell-Mobility in #607 - Handle recursively serializing a dataclasses as a dictionary. by @Jared-Newell-Mobility in #547 - v2.0.1 Action enums corrected by @Jared-Newell-Mobility in #580 - URL does not get converted from snake_case responder_url to camelCase responderURL by @Jared-Newell-Mobility in #592 - v1.6 Action Enum members corrected by @Jared-Newell-Mobility in #600 - Introduce Experimental Module For v2.1 by @Jared-Newell-Mobility in #605 - Bump to 1.0.0-rc.1 by @Jared-Newell-Mobility in #611 - fix typo in DataTypeEnum -> value_too_high by @d2avids in #612 - fix typo CostUpdated enum for 201 by @OSkrk in #620
- OCPP v1.6/v2.0.1 deprecate dataclasses from calls and call results with the suffix 'Payload' by @Jared-Newell-Mobility in mobilityhouse#584 - In GA, validate project against Python 3.11 and 3.12. by @Jared-Newell-Mobility in mobilityhouse#589 - drop support for python 3.7 by @Jared-Newell-Mobility in mobilityhouse#585 - Update Code Owners by @Jared-Newell-Mobility in mobilityhouse#588 - Revert "drop support for python 3.7" by @Jared-Newell-Mobility in mobilityhouse#597 - OCPP 2.0.1 Wrong data type in CostUpdated total_cost by @Jared-Newell-Mobility in mobilityhouse#596 - Update tests to use Call and CallResult without the suffix Payload by @Jared-Newell-Mobility in mobilityhouse#595 - Fix camel_to_snake_case for "v2x" by @Jared-Newell-Mobility in mobilityhouse#594 - Correct naming of members of v201.enums.AttributeType by @Jared-Newell-Mobility in mobilityhouse#578 - Drop support for python 3.7 by @Jared-Newell-Mobility in mobilityhouse#598 - Remove v1.6 deprecated enum variants by @Jared-Newell-Mobility in mobilityhouse#575 - Typo in CostUpdated Action mobilityhouse#435 by @Jared-Newell-Mobility in mobilityhouse#491- - Remove support for ocpp 2.0 by @Jared-Newell-Mobility in mobilityhouse#576 - v201.datatypes.ChargingNeedsType.request_energy_transfer is mistyped by @Jared-Newell-Mobility in mobilityhouse#496 - v201.enums.StatusInfoReasonType.invaild_schedule by @Jared-Newell-Mobility in mobilityhouse#521 - update to match Appendix 2. Standardized Units Of Measure by @Jared-Newell-Mobility in mobilityhouse#512 - v16/schemas/StopTransaction.json missing "Hertz" mobilityhouse#207 by @Jared-Newell-Mobility in mobilityhouse#497 - Correct v2g serialisation/deserialisation by @Jared-Newell-Mobility in mobilityhouse#606 - 2.0.1 dataclasses have a incorrect types that don't match carnality by @Jared-Newell-Mobility in mobilityhouse#529 - Readthedocs_configuration_is_outdated by @Jared-Newell-Mobility in mobilityhouse#608 - Readthedocs_configuration_is_outdated_config_update by @Jared-Newell-Mobility in mobilityhouse#609 - The serialisation of soc to SoC should not occur in camel case if it is existing at the beginning of a field by @Jared-Newell-Mobility in mobilityhouse#527 - Fix case conversion for soc in non "State of Charge" context by @Jared-Newell-Mobility in mobilityhouse#607 - Handle recursively serializing a dataclasses as a dictionary. by @Jared-Newell-Mobility in mobilityhouse#547 - v2.0.1 Action enums corrected by @Jared-Newell-Mobility in mobilityhouse#580 - URL does not get converted from snake_case responder_url to camelCase responderURL by @Jared-Newell-Mobility in mobilityhouse#592 - v1.6 Action Enum members corrected by @Jared-Newell-Mobility in mobilityhouse#600 - Introduce Experimental Module For v2.1 by @Jared-Newell-Mobility in mobilityhouse#605 - Bump to 1.0.0-rc.1 by @Jared-Newell-Mobility in mobilityhouse#611 - fix typo in DataTypeEnum -> value_too_high by @d2avids in mobilityhouse#612 - fix typo CostUpdated enum for 201 by @OSkrk in mobilityhouse#620
See issue #579