Skip to content

Commit

Permalink
Add OCPP 2.1 code generator
Browse files Browse the repository at this point in the history
This commit introduces a script that parses the JSON schemas for OCPP
2.1 and generate Python code.

Fixes: #452
  • Loading branch information
OrangeTux committed Jul 20, 2023
1 parent 0c7ccaa commit d55df35
Show file tree
Hide file tree
Showing 38 changed files with 4,325 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-python-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ runs:
shell: bash
run: |
pip install --upgrade pip
pip install --user "poetry==1.1.11"
pip install --user "poetry==1.5.1"
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Code Quality Check
shell: bash
run: make install && make tests
run: make install && make tests && make tests-format

- name: Poetry bump version, build and publish
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
- name: Code Quality Check
shell: bash
run: |
make install && make tests
make install && make tests && make tests-scripts
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# OCA doesn't allow to publish the schema's while draft hasn't been published.
ocpp/v21/schemas
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -110,3 +112,5 @@ venv.bak/

### OSX ###
*.DS_Store


10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help .check-pypi-envs .install-poetry update install docs tests build deploy
.PHONY: help .install-poetry build deploy docs format format-scripts install update tests tests-scripts

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -39,12 +39,20 @@ docs: .install-poetry
format: .install-poetry
poetry run isort ocpp tests && poetry run black ocpp tests

format-scripts: .install-poetry
poetry run isort --skip scripts/v21/tests/golden_files scripts/v21 && poetry run black --exclude scripts/v21/tests/golden_files scripts/v21/

tests: .install-poetry
poetry run black --check --diff ocpp tests
poetry run isort --check-only ocpp tests
poetry run flake8 ocpp tests
poetry run py.test -vvv --cov=ocpp --cov-report=term-missing tests/

tests-scripts: .install-poetry
poetry run black --check --diff --exclude scripts/v21/tests/golden_files scripts/v21/
poetry run isort --check-only --skip scripts/v21/tests/golden_files scripts/v21
poetry run pytest -vvv scripts/v21/tests

build: .install-poetry
poetry build

Expand Down
28 changes: 28 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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)
are supported.

This package has preliminary support for OCPP 2.1. See `OCPP 2.1 support`_ for more information.

You can find the documentation on `rtd`_.

Installation
Expand Down Expand Up @@ -190,6 +192,29 @@ To lower the logs for this package only use the following code:
logging.getLogger('ocpp').setLevel(level=logging.DEBUG)
logging.getLogger('ocpp').addHandler(logging.StreamHandler())
OCPP 2.1 support
----------------

The Open Charge Alliance (OCA) is working on OCPP 2.1. Only members of the OCA have
access to the `draft specification`_ and the corresponding `JSON schemas`_.

Support for OCPP 2.1 Draft 1, v0.40, 2023-05-11 is located at `ocpp/v21`_.
Unfortunately, the OCA does not allow to include the JSON Schemas at this moment.

The code in `ocpp/v21`_ is generated through a script. To generate the code yourself, run:


.. code-block:: shell
$ poetry run python scripts/v21/generate_implementation.py <path_to_json_schemas> --output=ocpp/v21
To execute the tests covering this script:

.. code-block:: shell
$ python run pytest scripts/v21/tests
License
-------

Expand All @@ -204,3 +229,6 @@ Attribution-NoDerivatives 4.0 International Public License.
.. _rtd: https://ocpp.readthedocs.io/en/latest/index.html
.. _The Mobility House: https://www.mobilityhouse.com/int_en/
.. _websockets: https://pypi.org/project/websockets/
.. _ocpp/v21: ocpp/v21
.. _draft specification: https://oca.causewaynow.com/wg/OCA-V2X/document/743
.. _JSON schemas: https://oca.causewaynow.com/wg/OCA-V2X/document/874
8 changes: 8 additions & 0 deletions ocpp/v21/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ocpp.charge_point import ChargePoint as cp
from ocpp.v21 import call, call_result


class ChargePoint(cp):
_call = call
_call_result = call_result
_ocpp_version = "2.1"
768 changes: 559 additions & 209 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sphinx = "^2.4.5"
black = "^22"
isort = "^5"
flake8 = "^5"
click = "^8.1.6"

[tool.black]
line-length = 88
Expand Down
Loading

0 comments on commit d55df35

Please sign in to comment.