From a89844d433370fc777a3a9d5ce29f7e8026b71a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 11 Jun 2024 00:47:44 +0200 Subject: [PATCH] test: add clear cache implementation example in ocpp2 server MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/ocpp-server/server.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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. -- 2.34.1