Skip to content

Commit

Permalink
Fix serialization of 'ocpp_csms_url' (#642)
Browse files Browse the repository at this point in the history
'camelCasing' `ocpp_csms_url` ends up as `ocppCSMSURL`. 
This is wrong. The spec uses
[ocppCsmsUrl](https://github.com/mobilityhouse/ocpp/blob/774a507b348da35de7dee81177665c8f88ff174b/ocpp/v201/schemas/SetNetworkProfileRequest.json#L146).

This commit fixes the conversion.
  • Loading branch information
OrangeTux authored Jun 3, 2024
1 parent 765799e commit 0d90fd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ 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("ocppCSMSURL", "ocpp_csms_url")
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 @@ -57,7 +56,10 @@ def snake_to_camel_case(data):
for key, value in data.items():
key = key.replace("soc", "SoC")
key = key.replace("_v2x", "V2X")
key = key.replace("ocpp_csms", "ocppCSMS")
# The spec uses inconsent casing for "csms" and "url".
# E.g. "OcppCsmsUrl" vs "ResponderURL" and "CSMSRootCertificate"
key = key.replace("ocpp_csms_url", "ocppCsmsUrl")
key = key.replace("csms", "CSMS")
key = key.replace("_url", "URL")
key = key.replace("soc", "SoC").replace("_SoCket", "Socket")
key = key.replace("_v2x", "V2X")
Expand Down
4 changes: 3 additions & 1 deletion tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def heartbeat(self, **kwargs):
({"responderURL": "foo.com"}, {"responder_url": "foo.com"}),
({"url": "foo.com"}, {"url": "foo.com"}),
({"ocppCSMSURL": "foo.com"}, {"ocpp_csms_url": "foo.com"}),
({"CSMSRootCertificate": "foo.com"}, {"csms_root_certificate": "foo.com"}),
({"InvalidURL": "foo.com"}, {"invalid_url": "foo.com"}),
({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}),
({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}),
Expand All @@ -94,7 +95,8 @@ def test_camel_to_snake_case(test_input, expected):
({"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"}),
({"ocpp_csms_url": "foo.com"}, {"ocppCsmsUrl": "foo.com"}),
({"csms_root_certificate": "foo.com"}, {"CSMSRootCertificate": "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 0d90fd4

Please sign in to comment.