Skip to content

Commit

Permalink
Merge branch 'master' into Wrong-dataclass-IdTokenType-(v201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared-Newell-Mobility authored Feb 7, 2024
2 parents 65c0aac + f1f9f17 commit 5bdd040
Show file tree
Hide file tree
Showing 168 changed files with 5,056 additions and 9,054 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @OrangeTux @tropxy
* @OrangeTux @tropxy @Jared-Newell-Mobility
3 changes: 2 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ jobs:
strategy:
matrix:
version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.version }}
Expand Down
45 changes: 44 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
# Change log

- [#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'
- [#591](https://github.com/mobilityhouse/ocpp/issues/591) Camel_to_snake_case doesn't handle v2x correctly
- [#593](https://github.com/mobilityhouse/ocpp/issues/593) Update tests to use Call and CallResult without the suffix Payload
- [#435](https://github.com/mobilityhouse/ocpp/issues/435) Typo in CostUpdated Action
- [#577](https://github.com/mobilityhouse/ocpp/issues/577) v2.0.1 AttributeType Enum Corrections
- [#340](https://github.com/mobilityhouse/ocpp/issues/340) 2.0.1 dataclasses have a incorrect types that don't match carnality
- [#510](https://github.com/mobilityhouse/ocpp/issues/510) v2.0.1 UnitOfMeasureType - Enums missing and update docstring to allow use for variableCharacteristics
- [#508](https://github.com/mobilityhouse/ocpp/issues/508) Exception - OccurrenceConstraintViolationError doc string correction

## BREAKING ##
- [#574](https://github.com/mobilityhouse/ocpp/issues/574) Remove v1.6 deprecated enum members - IMPORTANT see upgrade path [#574](https://github.com/mobilityhouse/ocpp/issues/574)
- [#498](https://github.com/mobilityhouse/ocpp/issues/498) Remove support for OCPP 2.0 - IMPORTANT SEE UPGRADE PATH [#498](https://github.com/mobilityhouse/ocpp/issues/498)


## 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
- [#518](https://github.com/mobilityhouse/ocpp/issues/518) OCPP 2.0.1 add additional reason codes from v1.3

## 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.
- [#537](https://github.com/mobilityhouse/ocpp/pull/537) Fix DataTransfer data types. Thanks [@mdwcrft](https://github.com/mdwcrft)

## 0.23.0 (2023-11-30)

- [#531] Feat: Add 1.6 security extension datatypes. Thanks [@proelke](https://github.com/proelke)
- [#528](https://github.com/mobilityhouse/ocpp/issues/528) v2.0.1 CertificateHashDataChainType childCertificateHashData requires the default of None.
- [#510](https://github.com/mobilityhouse/ocpp/issues/510) v2.0.1 UnitOfMeasureType - Enums missing and update docstring to allow use for variableCharacteristics.
- [#508](https://github.com/mobilityhouse/ocpp/issues/508) Exception - OccurrenceConstraintViolationError doc string correction.

## 0.22.0 (2023-11-03)

Expand All @@ -12,6 +53,8 @@
- [#504](https://github.com/mobilityhouse/ocpp/pull/504) Add missing tech_info attribute to v2.0.1 EventDataType. Thanks [@LokiHokie](https://github.com/LokiHokie)
- [#381](https://github.com/mobilityhouse/ocpp/issues/381) Add FormationError and OccurrenceConstraintViolationError.

- [#373](https://github.com/mobilityhouse/ocpp/issues/373) v201.datatypes.ChargingNeedsType.request_energy_transfer is mistyped

## 0.21.0 (2023-10-19)

- [#492] Minor fixes _handle_call doc string - Thanks @drc38
Expand Down
29 changes: 21 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ OCPP
----

Python package implementing the JSON version of the Open Charge Point Protocol
(OCPP). Currently OCPP 1.6 (errata v4), OCPP 2.0 and OCPP 2.0.1 (Final Version)
(OCPP). Currently OCPP 1.6 (errata v4), OCPP 2.0.1 (Edition 2 FINAL, 2022-12-15)
are supported.

You can find the documentation on `rtd`_.

The purpose of this library is to provide the building blocks to construct a
charging station/charge point and/or charging station management system
(CSMS)/central system. The library does not provide a completed solution, as any
implementation is specific for its intended use. The documents in this library
should be inspected, as these documents provided guidance on how best to
build a complete solution.

Note: "OCPP 2.0.1 contains fixes for all the known issues, to date, not only
the fixes to the messages. This version replaces OCPP 2.0. OCA advises
implementers of OCPP to no longer implement OCPP 2.0 and only use version
2.0.1 going forward."

Installation
------------

Expand All @@ -34,8 +46,9 @@ Or clone the project and install it manually using:
Quick start
-----------

Below you can find examples on how to create a simple OCPP 2.0 central system as
well as an OCPP 2.0 charge point.
Below you can find examples on how to create a simple OCPP 1.6 or 2.0.1 Central
System/CSMS as well as the respective OCPP 1.6 or 2.0.1
Charging Station/Charge Point.

.. note::

Expand All @@ -45,12 +58,12 @@ well as an OCPP 2.0 charge point.
$ pip install websockets
Central system
Charging Station Management System (CSMS) / Central System
~~~~~~~~~~~~~~

The code snippet below creates a simple OCPP 2.0 central system which is able
to handle BootNotification calls. You can find a detailed explanation of the
code in the `Central System documentation_`.
The code snippet below creates a simple OCPP 2.0.1 CSMS which
is able to handle BootNotification calls. You can find a detailed explanation of the
code in the `Central System documentation`_.


.. code-block:: python
Expand Down Expand Up @@ -121,7 +134,7 @@ code in the `Central System documentation_`.
if __name__ == '__main__':
asyncio.run(main())
Charge point
Charging Station / Charge point
~~~~~~~~~~~~

.. code-block:: python
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.22.0"
release = "0.26.0"


# -- General configuration ---------------------------------------------------
Expand Down
Binary file removed docs/v201/Changelog OCPP 2.0 - 2.0.1.pdf
Binary file not shown.
Binary file added docs/v201/OCPP-2.0.1_edition2_errata_2023-12.pdf
Binary file not shown.
78 changes: 0 additions & 78 deletions examples/v20/central_system.py

This file was deleted.

53 changes: 0 additions & 53 deletions examples/v20/charge_point.py

This file was deleted.

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
31 changes: 26 additions & 5 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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")
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 All @@ -44,7 +45,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 +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")
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 +226,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,15 +266,23 @@ 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:
# '_on_after' hooks are not required. Therefore ignore exception
# when no '_on_after' hook is installed.
pass
return response

async def call(self, payload, suppress=True, unique_id=None):
"""
Expand Down Expand Up @@ -296,9 +312,14 @@ async def call(self, payload, suppress=True, unique_id=None):
unique_id if unique_id is not None else str(self._unique_id_generator())
)

action_name = payload.__class__.__name__
# Due to deprecated call and callresults, remove in the future.
if "Payload" in payload.__class__.__name__:
action_name = payload.__class__.__name__[:-7]

call = Call(
unique_id=unique_id,
action=payload.__class__.__name__[:-7],
action=action_name,
payload=remove_nones(camel_case_payload),
)

Expand Down
4 changes: 2 additions & 2 deletions ocpp/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def __eq__(self, other):

def __repr__(self):
return (
f"<{self.__class__.__name__} - description={self.description},"
f"<{self.__class__.__name__} - description={self.description}, "
f" details={self.details}>"
)

def __str__(self):
return f"{self.__class__.__name__}: {self.description}," f" {self.details}"
return f"{self.__class__.__name__}: {self.description}, " f" {self.details}"


class NotImplementedError(OCPPError):
Expand Down
Loading

0 comments on commit 5bdd040

Please sign in to comment.