Skip to content

Commit

Permalink
URL does not get converted from snake_case responder_url to camelCase…
Browse files Browse the repository at this point in the history
… responderURL (#592)

see issue #590
  • Loading branch information
Jared-Newell-Mobility authored Feb 14, 2024
1 parent 144b544 commit 9fb5769
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 Down
6 changes: 6 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 @@ -53,6 +55,10 @@ def snake_to_camel_case(data):
if isinstance(data, dict):
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")
key = key.replace("soc", "SoC").replace("_SoCket", "Socket")
key = key.replace("_v2x", "V2X")
key = key.replace("soc_limit_reached", "SOCLimitReached")
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 @@ -64,6 +64,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}),
({"webSocketPingInterval": 200}, {"web_socket_ping_interval": 200}),
Expand All @@ -87,6 +91,10 @@ def test_camel_to_snake_case(test_input, expected):
({"soc_limit_reached": 200}, {"SoCLimitReached": 200}),
({"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"}),
({"web_socket_ping_interval": 200}, {"webSocketPingInterval": 200}),
({"sign_v2g_certificate": 200}, {"signV2GCertificate": 200}),
(
Expand Down

0 comments on commit 9fb5769

Please sign in to comment.