Skip to content

Commit

Permalink
Correct v2g serialisation/deserialisation (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared-Newell-Mobility authored Feb 9, 2024
1 parent 7f1d59e commit 489a6cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Change log
- [#602](https://github.com/mobilityhouse/ocpp/issues/602) Correct v2g serialisation/deserialisation
- [#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'
Expand Down
4 changes: 2 additions & 2 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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")
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 @@ -54,7 +54,7 @@ def snake_to_camel_case(data):
camel_case_dict = {}
for key, value in data.items():
key = key.replace("soc", "SoC")
key = key.replace("_v2x", "V2X")
key = key.replace("_v2x", "V2X").replace("_v2g", "V2G")
components = key.split("_")
key = components[0] + "".join(x[:1].upper() + x[1:] for x in components[1:])
camel_case_dict[key] = snake_to_camel_case(value)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def heartbeat(self, **kwargs):
({"fullSoC": 100}, {"full_soc": 100}),
({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}),
({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}),
({"signV2GCertificate": 200}, {"sign_v2g_certificate": 200}),
(
{"v2gCertificateInstallationEnabled": 200},
{"v2g_certificate_installation_enabled": 200},
),
],
)
def test_camel_to_snake_case(test_input, expected):
Expand All @@ -68,6 +73,11 @@ def test_camel_to_snake_case(test_input, expected):
({"full_soc": 100}, {"fullSoC": 100}),
({"ev_min_v2x_energy_request": 200}, {"evMinV2XEnergyRequest": 200}),
({"v2x_charging_ctrlr": 200}, {"v2xChargingCtrlr": 200}),
({"sign_v2g_certificate": 200}, {"signV2GCertificate": 200}),
(
{"v2g_certificate_installation_enabled": 200},
{"v2gCertificateInstallationEnabled": 200},
),
],
)
def test_snake_to_camel_case(test_input, expected):
Expand Down

0 comments on commit 489a6cc

Please sign in to comment.