Skip to content
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

URL does not get converted from snake_case responder_url to camelCase responderURL #592

Merged
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [#557](https://github.com/mobilityhouse/ocpp/issues/557) OCPP 2.0.1 Wrong data type in CostUpdated total_cost
- [#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'
- [#590](https://github.com/mobilityhouse/ocpp/pull/336) snake_to_camel_case url to URL does not get converted correctly
- [#591](https://github.com/mobilityhouse/ocpp/issues/591) Camel_to_snake_case doesn't handle v2x correctly
- [#593](https://github.com/mobilityhouse/ocpp/issues/593) Update tests to use Call and CallResult without the suffix Payload
- [#435](https://github.com/mobilityhouse/ocpp/issues/435) Typo in CostUpdated Action
Expand All @@ -16,7 +17,6 @@
- [#574](https://github.com/mobilityhouse/ocpp/issues/574) Remove v1.6 deprecated enum members - IMPORTANT see upgrade path [#574](https://github.com/mobilityhouse/ocpp/issues/574)
- [#498](https://github.com/mobilityhouse/ocpp/issues/498) Remove support for OCPP 2.0 - IMPORTANT SEE UPGRADE PATH [#498](https://github.com/mobilityhouse/ocpp/issues/498)


## 0.26.0 (2024-01-17)

- [#544](https://github.com/mobilityhouse/ocpp/issues/544) ocpp/charge_point.py - Pass `Call.unique_id` to the `on` and `after` routing handlers.
Expand Down
5 changes: 5 additions & 0 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def camel_to_snake_case(data):
if isinstance(data, dict):
snake_case_dict = {}
for key, value in data.items():
key = key.replace("ocppCSMS", "ocpp_csms")
key = key.replace("V2X", "_v2x")
key = key.replace("V2X", "_v2x").replace("V2G", "_v2g")
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", key)
key = re.sub("([a-z0-9])([A-Z])(?=\\S)", r"\1_\2", s1).lower()
Expand Down Expand Up @@ -54,6 +56,9 @@ def snake_to_camel_case(data):
camel_case_dict = {}
for key, value in data.items():
key = key.replace("soc", "SoC")
key = key.replace("_v2x", "V2X")
key = key.replace("ocpp_csms", "ocppCSMS")
key = key.replace("_url", "URL")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue with this approach is another field, as I mentioned in my other PR. The ocppCsmsUrl field in a SetNetworkProfileRequest will fail due to this change. I would suggest adding test cases for any usage of URL in the spec.

Copy link
Collaborator

@OrangeTux OrangeTux Feb 5, 2024

Choose a reason for hiding this comment

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

I believe these are all attributes that include url:

$ grep -i "url" ocpp/v201/*.py
ocpp/v201/datatypes.py:    ocpp_csms_url: str
ocpp/v201/datatypes.py:    responder_url: str
ocpp/v201/enums.py:    invalid_url = "InvalidURL"

key = key.replace("_v2x", "V2X").replace("_v2g", "V2G")
components = key.split("_")
key = components[0] + "".join(x[:1].upper() + x[1:] for x in components[1:])
Expand Down
8 changes: 8 additions & 0 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def heartbeat(self, **kwargs):
[
({"transactionId": "74563478"}, {"transaction_id": "74563478"}),
({"fullSoC": 100}, {"full_soc": 100}),
({"responderURL": "foo.com"}, {"responder_url": "foo.com"}),
({"url": "foo.com"}, {"url": "foo.com"}),
({"ocppCSMSURL": "foo.com"}, {"ocpp_csms_url": "foo.com"}),
({"InvalidURL": "foo.com"}, {"invalid_url": "foo.com"}),
({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}),
({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}),
({"signV2GCertificate": 200}, {"sign_v2g_certificate": 200}),
Expand All @@ -73,6 +77,10 @@ def test_camel_to_snake_case(test_input, expected):
({"full_soc": 100}, {"fullSoC": 100}),
({"ev_min_v2x_energy_request": 200}, {"evMinV2XEnergyRequest": 200}),
({"v2x_charging_ctrlr": 200}, {"v2xChargingCtrlr": 200}),
({"responder_url": "foo.com"}, {"responderURL": "foo.com"}),
({"url": "foo.com"}, {"url": "foo.com"}),
({"ocpp_csms_url": "foo.com"}, {"ocppCSMSURL": "foo.com"}),
({"invalid_url": "foo.com"}, {"invalidURL": "foo.com"}),
({"sign_v2g_certificate": 200}, {"signV2GCertificate": 200}),
(
{"v2g_certificate_installation_enabled": 200},
Expand Down
Loading