Skip to content

Commit

Permalink
Merge branch 'master' into revert_type_hint_change_for_DataTransfer_data
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmclarty authored Jan 17, 2024
2 parents a71fc59 + 020188c commit 3004e19
Show file tree
Hide file tree
Showing 11 changed files with 771 additions and 491 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change log

## 0.26.0 (2024-01-17)

- [#544](https://github.com/mobilityhouse/ocpp/issues/544) ocpp/charge_point.py - Pass `Call.unique_id` to the `on` and `after` routing handlers.
- [#559](https://github.com/mobilityhouse/ocpp/issues/559) Update project dependencies as of 22-12-2023
- [#447](https://github.com/mobilityhouse/ocpp/issues/447) v16, v201 - Make formatting of enums in py3.11 consistent with earlier Python versions
- [#421](https://github.com/mobilityhouse/ocpp/issues/421) Type of v16.datatypes.SampledValue.context is incorrect

## 0.25.0 (2024-01-08)

- [#366](https://github.com/mobilityhouse/ocpp/issues/366) Fix type hint of OCPP 1.6 ChangeConfiguration.value
- [#431](https://github.com/mobilityhouse/ocpp/issues/431) Attributes with 'v2x' are serialized as 'V2x', but should be serialized as 'V2X'
- [#554](https://github.com/mobilityhouse/ocpp/issues/554) OCPP 2.0.1 Edition 2 Errata 2023-12 document added
- [#548](https://github.com/mobilityhouse/ocpp/issues/548) OCPP 2.0.1 MessageInfoType attribute name correction
- [#300](https://github.com/mobilityhouse/ocpp/issues/300) OCPP 2.0.1 add reference components and variables
Expand All @@ -8,6 +19,7 @@

## 0.24.0 (2023-12-07)


- [#539](https://github.com/mobilityhouse/ocpp/issues/539) feat: Add ChargePoint._handle_call return value. Thanks [@wafa-yah](https://github.com/wafa-yah)
- [#266](https://github.com/mobilityhouse/ocpp/issues/266) fix: Central System documentation link.
- [#516](https://github.com/mobilityhouse/ocpp/issues/516) OCPP 2.0.1 add additional security events from v1.3.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Auke Willem Oosterhoff"

# The full version, including alpha/beta/rc tags
release = "0.24.0"
release = "0.26.0"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions examples/v201/central_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ async def on_connect(websocket, path):
try:
requested_protocols = websocket.request_headers["Sec-WebSocket-Protocol"]
except KeyError:
logging.info("Client hasn't requested any Subprotocol. " "Closing Connection")
return await websocket.close()
logging.error("Client hasn't requested any Subprotocol. Closing Connection")
return await websocket.close()
if websocket.subprotocol:
Expand Down
22 changes: 18 additions & 4 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def camel_to_snake_case(data):

def snake_to_camel_case(data):
"""
Convert all keys of a all dictionaries inside given argument from
Convert all keys of all dictionaries inside given argument from
snake_case to camelCase.
Inspired by: https://stackoverflow.com/a/19053800/1073222
Expand All @@ -53,6 +53,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")
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 @@ -224,9 +225,15 @@ async def _handle_call(self, msg):
handler = handlers["_on_action"]
except KeyError:
_raise_key_error(msg.action, self._ocpp_version)

handler_signature = inspect.signature(handler)
call_unique_id_required = "call_unique_id" in handler_signature.parameters
try:
response = handler(**snake_case_payload)
# call_unique_id should be passed as kwarg only if is defined explicitly
# in the handler signature
if call_unique_id_required:
response = handler(**snake_case_payload, call_unique_id=msg.unique_id)
else:
response = handler(**snake_case_payload)
if inspect.isawaitable(response):
response = await response
except Exception as e:
Expand Down Expand Up @@ -258,9 +265,16 @@ async def _handle_call(self, msg):

try:
handler = handlers["_after_action"]
handler_signature = inspect.signature(handler)
call_unique_id_required = "call_unique_id" in handler_signature.parameters
# call_unique_id should be passed as kwarg only if is defined explicitly
# in the handler signature
if call_unique_id_required:
response = handler(**snake_case_payload, call_unique_id=msg.unique_id)
else:
response = handler(**snake_case_payload)
# Create task to avoid blocking when making a call inside the
# after handler
response = handler(**snake_case_payload)
if inspect.isawaitable(response):
asyncio.ensure_future(response)
except KeyError:
Expand Down
4 changes: 2 additions & 2 deletions ocpp/v16/call.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional

from ocpp.v16.enums import (
AvailabilityType,
Expand Down Expand Up @@ -55,7 +55,7 @@ class ChangeAvailabilityPayload:
@dataclass
class ChangeConfigurationPayload:
key: str
value: Any
value: str


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion ocpp/v16/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SampledValue:
"""

value: str
context: ReadingContext
context: Optional[ReadingContext] = None
format: Optional[ValueFormat] = None
measurand: Optional[Measurand] = None
phase: Optional[Phase] = None
Expand Down
Loading

0 comments on commit 3004e19

Please sign in to comment.