Skip to content

Commit

Permalink
Merge branch 'master' into handle_responder_url
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeTux authored Dec 23, 2022
2 parents 6ed30cf + e4495f1 commit e5d31cf
Show file tree
Hide file tree
Showing 48 changed files with 1,219 additions and 1,054 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
inline-quotes = "
4 changes: 4 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- name: Setup the Python Environment by installing Poetry
uses: ./.github/actions/setup-python-build-env

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

- name: Poetry bump version, build and publish
shell: bash
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: [3.7, 3.8, 3.9, 3.10.0]
version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.version }}
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Therefore, 0.13.0 is not listed in this CHANGELOG.md

## 0.10.0 (2021-09-16)

* [#240](https://github.com/mobilityhouse/ocpp/issues/240) Remove depreciated function `get_schema_code()`. Thanks [@proelke](https://github.com/proelke)
* [#249](https://github.com/mobilityhouse/ocpp/issues/249) Add OCPP v2.0.1 data types. Thanks [@proelke](https://github.com/proelke)
* [#249](https://github.com/mobilityhouse/ocpp/issues/249) Remove depreciated function `get_schema_code()`. Thanks [@proelke](https://github.com/proelke)
* [#240](https://github.com/mobilityhouse/ocpp/issues/240) Add OCPP v2.0.1 data types. Thanks [@proelke](https://github.com/proelke)

## 0.9.0 (2021-09-02)

Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
recursive-exclude tests *
exclude requirements_dev.txt
include requirements.txt
recursive-include ocpp/v16/schemas *.json
recursive-include ocpp/v20/schemas *.json
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ install: .install-poetry
docs: .install-poetry
poetry run sphinx-build -b html docs/source docs/build

format: .install-poetry
poetry run isort ocpp tests && poetry run black ocpp tests

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/

Expand Down
44 changes: 24 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ code in the `Central System documentation_`.
from ocpp.routing import on
from ocpp.v201 import ChargePoint as cp
from ocpp.v201 import call_result
from ocpp.v201.enums import RegistrationStatusType
logging.basicConfig(level=logging.INFO)
Expand All @@ -73,7 +74,7 @@ code in the `Central System documentation_`.
return call_result.BootNotificationPayload(
current_time=datetime.utcnow().isoformat(),
interval=10,
status='Accepted'
status=RegistrationStatusType.accepted
)
Expand All @@ -87,6 +88,8 @@ code in the `Central System documentation_`.
except KeyError:
logging.info("Client hasn't requested any Subprotocol. "
"Closing Connection")
return await websocket.close()
if websocket.subprotocol:
logging.info("Protocols Matched: %s", websocket.subprotocol)
else:
Expand Down Expand Up @@ -124,6 +127,8 @@ Charge point
.. code-block:: python
import asyncio
from ocpp.v201.enums import RegistrationStatusType
import logging
import websockets
Expand All @@ -135,33 +140,32 @@ Charge point
class ChargePoint(cp):
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charging_station={
'model': 'Wallbox XYZ',
'vendor_name': 'anewone'
},
reason="PowerUp"
)
response = await self.call(request)
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charging_station={
'model': 'Wallbox XYZ',
'vendor_name': 'anewone'
},
reason="PowerUp"
)
response = await self.call(request)
if response.status == 'Accepted':
print("Connected to central system.")
if response.status == RegistrationStatusType.accepted:
print("Connected to central system.")
async def main():
async with websockets.connect(
'ws://localhost:9000/CP_1',
subprotocols=['ocpp2.0.1']
) as ws:
cp = ChargePoint('CP_1', ws)
async with websockets.connect(
'ws://localhost:9000/CP_1',
subprotocols=['ocpp2.0.1']
) as ws:
cp = ChargePoint('CP_1', ws)
await asyncio.gather(cp.start(), cp.send_boot_notification())
await asyncio.gather(cp.start(), cp.send_boot_notification())
if __name__ == '__main__':
asyncio.run(main())
asyncio.run(main())
Debugging
---------
Expand Down
23 changes: 11 additions & 12 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,45 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../'))

sys.path.insert(0, os.path.abspath("../../"))


# -- Project information -----------------------------------------------------

project = 'OCPP'
copyright = '2022, Auke Willem Oosterhoff'
author = 'Auke Willem Oosterhoff'
project = "OCPP"
copyright = "2022, Auke Willem Oosterhoff"
author = "Auke Willem Oosterhoff"

# The full version, including alpha/beta/rc tags
release = '0.15.0'
release = "0.15.0"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc'
]
extensions = ["sphinx.ext.autodoc"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

master_doc = 'index'
master_doc = "index"

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
Binary file added docs/v16/ocpp-1.6 edition 2.pdf
Binary file not shown.
Binary file added docs/v16/ocpp-1.6-errata-sheet.pdf
Binary file not shown.
Binary file added docs/v16/ocpp-j-1.6-errata-sheet.pdf
Binary file not shown.
35 changes: 17 additions & 18 deletions examples/v16/central_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,61 @@
print()
print(" $ pip install websockets")
import sys

sys.exit(1)

from ocpp.routing import on
from ocpp.v16 import ChargePoint as cp
from ocpp.v16.enums import Action, RegistrationStatus
from ocpp.v16 import call_result
from ocpp.v16.enums import Action, RegistrationStatus

logging.basicConfig(level=logging.INFO)


class ChargePoint(cp):
@on(Action.BootNotification)
def on_boot_notification(self, charge_point_vendor: str, charge_point_model: str, **kwargs):
def on_boot_notification(
self, charge_point_vendor: str, charge_point_model: str, **kwargs
):
return call_result.BootNotificationPayload(
current_time=datetime.utcnow().isoformat(),
interval=10,
status=RegistrationStatus.accepted
status=RegistrationStatus.accepted,
)


async def on_connect(websocket, path):
""" For every new charge point that connects, create a ChargePoint
"""For every new charge point that connects, create a ChargePoint
instance and start listening for messages.
"""
try:
requested_protocols = websocket.request_headers[
'Sec-WebSocket-Protocol']
requested_protocols = websocket.request_headers["Sec-WebSocket-Protocol"]
except KeyError:
logging.error(
"Client hasn't requested any Subprotocol. Closing Connection"
)
logging.error("Client hasn't requested any Subprotocol. Closing Connection")
return await websocket.close()
if websocket.subprotocol:
logging.info("Protocols Matched: %s", websocket.subprotocol)
else:
# In the websockets lib if no subprotocols are supported by the
# client and the server, it proceeds without a subprotocol,
# so we have to manually close the connection.
logging.warning('Protocols Mismatched | Expected Subprotocols: %s,'
' but client supports %s | Closing connection',
websocket.available_subprotocols,
requested_protocols)
logging.warning(
"Protocols Mismatched | Expected Subprotocols: %s,"
" but client supports %s | Closing connection",
websocket.available_subprotocols,
requested_protocols,
)
return await websocket.close()

charge_point_id = path.strip('/')
charge_point_id = path.strip("/")
cp = ChargePoint(charge_point_id, websocket)

await cp.start()


async def main():
server = await websockets.serve(
on_connect,
'0.0.0.0',
9000,
subprotocols=['ocpp1.6']
on_connect, "0.0.0.0", 9000, subprotocols=["ocpp1.6"]
)

logging.info("Server Started listening to new connections...")
Expand Down
11 changes: 5 additions & 6 deletions examples/v16/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
print()
print(" $ pip install websockets")
import sys

sys.exit(1)


from ocpp.v16 import call
from ocpp.v16 import ChargePoint as cp
from ocpp.v16 import call
from ocpp.v16.enums import RegistrationStatus

logging.basicConfig(level=logging.INFO)
Expand All @@ -22,8 +23,7 @@
class ChargePoint(cp):
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charge_point_model="Optimus",
charge_point_vendor="The Mobility House"
charge_point_model="Optimus", charge_point_vendor="The Mobility House"
)

response = await self.call(request)
Expand All @@ -34,11 +34,10 @@ async def send_boot_notification(self):

async def main():
async with websockets.connect(
'ws://localhost:9000/CP_1',
subprotocols=['ocpp1.6']
"ws://localhost:9000/CP_1", subprotocols=["ocpp1.6"]
) as ws:

cp = ChargePoint('CP_1', ws)
cp = ChargePoint("CP_1", ws)

await asyncio.gather(cp.start(), cp.send_boot_notification())

Expand Down
Loading

0 comments on commit e5d31cf

Please sign in to comment.