Skip to content

Commit 0d90fd4

Browse files
authored
Fix serialization of 'ocpp_csms_url' (#642)
'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.
1 parent 765799e commit 0d90fd4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ocpp/charge_point.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def camel_to_snake_case(data):
2525
if isinstance(data, dict):
2626
snake_case_dict = {}
2727
for key, value in data.items():
28-
key = key.replace("ocppCSMS", "ocpp_csms")
29-
key = key.replace("V2X", "_v2x")
28+
key = key.replace("ocppCSMSURL", "ocpp_csms_url")
3029
key = key.replace("V2X", "_v2x").replace("V2G", "_v2g")
3130
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", key)
3231
key = re.sub("([a-z0-9])([A-Z])(?=\\S)", r"\1_\2", s1).lower()
@@ -57,7 +56,10 @@ def snake_to_camel_case(data):
5756
for key, value in data.items():
5857
key = key.replace("soc", "SoC")
5958
key = key.replace("_v2x", "V2X")
60-
key = key.replace("ocpp_csms", "ocppCSMS")
59+
# The spec uses inconsent casing for "csms" and "url".
60+
# E.g. "OcppCsmsUrl" vs "ResponderURL" and "CSMSRootCertificate"
61+
key = key.replace("ocpp_csms_url", "ocppCsmsUrl")
62+
key = key.replace("csms", "CSMS")
6163
key = key.replace("_url", "URL")
6264
key = key.replace("soc", "SoC").replace("_SoCket", "Socket")
6365
key = key.replace("_v2x", "V2X")

tests/test_charge_point.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def heartbeat(self, **kwargs):
6868
({"responderURL": "foo.com"}, {"responder_url": "foo.com"}),
6969
({"url": "foo.com"}, {"url": "foo.com"}),
7070
({"ocppCSMSURL": "foo.com"}, {"ocpp_csms_url": "foo.com"}),
71+
({"CSMSRootCertificate": "foo.com"}, {"csms_root_certificate": "foo.com"}),
7172
({"InvalidURL": "foo.com"}, {"invalid_url": "foo.com"}),
7273
({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}),
7374
({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}),
@@ -94,7 +95,8 @@ def test_camel_to_snake_case(test_input, expected):
9495
({"v2x_charging_ctrlr": 200}, {"v2xChargingCtrlr": 200}),
9596
({"responder_url": "foo.com"}, {"responderURL": "foo.com"}),
9697
({"url": "foo.com"}, {"url": "foo.com"}),
97-
({"ocpp_csms_url": "foo.com"}, {"ocppCSMSURL": "foo.com"}),
98+
({"ocpp_csms_url": "foo.com"}, {"ocppCsmsUrl": "foo.com"}),
99+
({"csms_root_certificate": "foo.com"}, {"CSMSRootCertificate": "foo.com"}),
98100
({"invalid_url": "foo.com"}, {"invalidURL": "foo.com"}),
99101
({"web_socket_ping_interval": 200}, {"webSocketPingInterval": 200}),
100102
({"sign_v2g_certificate": 200}, {"signV2GCertificate": 200}),

0 commit comments

Comments
 (0)