X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Focpp-server%2Fserver.py;h=c8bdd0851ab2cfee8a5bc0a1e696eecf26934356;hb=b738a0fc1c620f3836d868235af16dfb61a91a50;hp=5738c7e33ce778fcf401c1bdb7ac501f9944c3d1;hpb=299eb3fafb21481e38e963ff6080d0822ae6a3ae;p=e-mobility-charging-stations-simulator.git diff --git a/tests/ocpp-server/server.py b/tests/ocpp-server/server.py index 5738c7e3..c8bdd085 100644 --- a/tests/ocpp-server/server.py +++ b/tests/ocpp-server/server.py @@ -2,7 +2,6 @@ import argparse import asyncio import logging from datetime import datetime, timezone -from functools import partial from threading import Timer import ocpp.v201 @@ -127,7 +126,6 @@ class ChargePoint(ocpp.v201.ChargePoint): logging.info("%s filed", Action.GetBaseReport) - # Function to send OCPP command async def send_ocpp_command(cp, command_name, delay=None, period=None): try: @@ -147,7 +145,9 @@ async def send_ocpp_command(cp, command_name, delay=None, period=None): await asyncio.sleep(delay) if period: - my_timer = RepeatTimer(period, asyncio.create_task, [cp.send_ocpp_command(command_name)]) + my_timer = RepeatTimer( + period, asyncio.create_task, [cp.send_ocpp_command(command_name)] + ) my_timer.start() @@ -184,6 +184,7 @@ async def on_connect(websocket, path): ChargePoints.remove(cp) logging.debug("Connected ChargePoint(s): %d", len(ChargePoints)) + # Main function to start the WebSocket server. async def main(): # Define argument parser @@ -192,7 +193,6 @@ async def main(): parser.add_argument("--delay", type=int, help="Delay in seconds") parser.add_argument("--period", type=int, help="Period in seconds") - # Create the WebSocket server and specify the handler for new connections. server = await websockets.serve( on_connect, @@ -208,7 +208,7 @@ async def main(): for cp in ChargePoints: asyncio.create_task( send_ocpp_command(cp, args.command, args.delay, args.period) - ) + ) # Wait for the server to close (runs indefinitely). await server.wait_closed()