diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac3c6778..9cbda533c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ocpp/charge_point.py b/ocpp/charge_point.py index c86369f57..143cf8a2f 100644 --- a/ocpp/charge_point.py +++ b/ocpp/charge_point.py @@ -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() @@ -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") diff --git a/tests/test_charge_point.py b/tests/test_charge_point.py index e5bf78ad2..ae38e446d 100644 --- a/tests/test_charge_point.py +++ b/tests/test_charge_point.py @@ -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}), @@ -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}), (