From: Jérôme Benoit Date: Mon, 10 Jun 2024 22:47:44 +0000 (+0200) Subject: test: add clear cache implementation example in ocpp2 server X-Git-Tag: v1.3.7~80 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a89844d433370fc777a3a9d5ce29f7e8026b71a8;p=e-mobility-charging-stations-simulator.git test: add clear cache implementation example in ocpp2 server Signed-off-by: Jérôme Benoit --- diff --git a/tests/ocpp-server/server.py b/tests/ocpp-server/server.py index 4dc72727..28f1f1c7 100644 --- a/tests/ocpp-server/server.py +++ b/tests/ocpp-server/server.py @@ -3,18 +3,18 @@ import logging from datetime import datetime, timezone from typing import Sequence +import ocpp.v201 import websockets from ocpp.routing import on -from ocpp.v201 import ChargePoint as cp from ocpp.v201 import call_result -from ocpp.v201.enums import RegistrationStatusType +from ocpp.v201.enums import RegistrationStatusType, ClearCacheStatusType # Setting up the logging configuration to display debug level messages. logging.basicConfig(level=logging.DEBUG) # Define a ChargePoint class inheriting from the OCPP 2.0.1 ChargePoint class. -class ChargePoint(cp): +class ChargePoint(ocpp.v201.ChargePoint): # Message handlers to receive OCPP message. @on('BootNotification') async def on_boot_notification(self, charging_station, reason, **kwargs): @@ -28,6 +28,14 @@ class ChargePoint(cp): ) # Request handlers to emit OCPP messages. + async def send_clear_cache(self): + request = ocpp.v201.call.ClearCache() + response = await self.call(request) + + if response.status == ClearCacheStatusType.accepted: + logging.info("Cache cleared successfully") + else: + logging.info("Cache clearing failed") # Function to handle new WebSocket connections.