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

add executor to validate_payload #652

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ async def _handle_call(self, msg):
return

if not handlers.get("_skip_schema_validation", False):
validate_payload(msg, self._ocpp_version)
await asyncio.get_event_loop().run_in_executor(
None, validate_payload, msg, self._ocpp_version
)
# OCPP uses camelCase for the keys in the payload. It's more pythonic
# to use snake_case for keyword arguments. Therefore the keys must be
# 'translated'. Some examples:
Expand Down Expand Up @@ -337,7 +339,9 @@ async def _handle_call(self, msg):
response = msg.create_call_result(camel_case_payload)

if not handlers.get("_skip_schema_validation", False):
validate_payload(response, self._ocpp_version)
await asyncio.get_event_loop().run_in_executor(
None, validate_payload, response, self._ocpp_version
)

await self._send(response.to_json())

Expand Down Expand Up @@ -406,7 +410,9 @@ async def call(
)

if not skip_schema_validation:
validate_payload(call, self._ocpp_version)
await asyncio.get_event_loop().run_in_executor(
None, validate_payload, call, self._ocpp_version
)

# Use a lock to prevent make sure that only 1 message can be send at a
# a time.
Expand All @@ -429,7 +435,9 @@ async def call(
raise response.to_exception()
elif not skip_schema_validation:
response.action = call.action
validate_payload(response, self._ocpp_version)
await asyncio.get_event_loop().run_in_executor(
None, validate_payload, response, self._ocpp_version
)

snake_case_payload = camel_to_snake_case(response.payload)
# Create the correct Payload instance based on the received payload. If
Expand Down
Loading