From efe2d5a8ffa13aaea67f786a56075a63f017f1c0 Mon Sep 17 00:00:00 2001 From: Jared-Newell-Mobility <119603687+Jared-Newell-Mobility@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:01:56 +0100 Subject: [PATCH] Fix camel_to_snake_case for "v2x" (#594) see issue https://github.com/mobilityhouse/ocpp/issues/591 --- CHANGELOG.md | 1 + ocpp/charge_point.py | 1 + tests/test_charge_point.py | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56837bca..bdbdd26d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,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' +- [#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 ## 0.26.0 (2024-01-17) diff --git a/ocpp/charge_point.py b/ocpp/charge_point.py index 0e9337558..3b985df0d 100644 --- a/ocpp/charge_point.py +++ b/ocpp/charge_point.py @@ -25,6 +25,7 @@ def camel_to_snake_case(data): if isinstance(data, dict): snake_case_dict = {} for key, value in data.items(): + key = key.replace("V2X", "_v2x") 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() diff --git a/tests/test_charge_point.py b/tests/test_charge_point.py index cefcb1860..87052b1e9 100644 --- a/tests/test_charge_point.py +++ b/tests/test_charge_point.py @@ -52,6 +52,8 @@ def heartbeat(self, **kwargs): [ ({"transactionId": "74563478"}, {"transaction_id": "74563478"}), ({"fullSoC": 100}, {"full_soc": 100}), + ({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}), + ({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}), ], ) def test_camel_to_snake_case(test_input, expected):