Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle responder_url edge case #336

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
#
Expand Down
1 change: 1 addition & 0 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading