diff --git a/ocpp/charge_point.py b/ocpp/charge_point.py index 5e31f3fe7..88ab1781e 100644 --- a/ocpp/charge_point.py +++ b/ocpp/charge_point.py @@ -52,7 +52,13 @@ def snake_to_camel_case(data): if isinstance(data, dict): camel_case_dict = {} for key, value in data.items(): - key = key.replace("soc", "SoC") + # These are edge cases in the 2.0.1 spec that don't get handled + # well + if 'soc' in key: + key = key.replace('soc', 'SoC') + elif 'responder_url' in key: + key = key.replace('url', 'URL') + 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) @@ -132,6 +138,8 @@ def __init__(self, id, connection, response_timeout=30): self.id = id # The maximum time in seconds it may take for a CP to respond to a + +Footer # CALL. An asyncio.TimeoutError will be raised if this limit has been # exceeded. self._response_timeout = response_timeout @@ -242,6 +250,8 @@ async def _handle_call(self, msg): # which were not set and have a default value of None response_payload = remove_nones(temp_response_payload) +Footer + # The response payload must be 'translated' from snake_case to # camelCase. So: # diff --git a/tests/test_charge_point.py b/tests/test_charge_point.py index de505baad..ffab46310 100644 --- a/tests/test_charge_point.py +++ b/tests/test_charge_point.py @@ -65,6 +65,7 @@ def test_camel_to_snake_case(test_input, expected): [ ({"transaction_id": "74563478"}, {"transactionId": "74563478"}), ({"full_soc": 100}, {"fullSoC": 100}), + ({"responder_url": "foo.com"}, {"responderURL": "foo.com"}) ], ) def test_snake_to_camel_case(test_input, expected):