]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(ocpp): move ClearCache handler to OCPP 1.6 service
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Feb 2026 05:45:13 +0000 (06:45 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Feb 2026 05:45:13 +0000 (06:45 +0100)
Auth cache implementation differs between OCPP versions, so shared
handler in parent class was not appropriate.

src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts

index bcb87fc67a4a5ebde4a92478a013f784516e2e2c..9fe6c662d3a37483f5ccab94fc00f2ebbbee75d6 100644 (file)
@@ -21,6 +21,7 @@ import {
   checkChargingStationState,
   getConfigurationKey,
   getConnectorChargingProfiles,
+  getIdTagsFile,
   prepareChargingProfileKind,
   removeExpiredReservations,
   resetAuthorizeConnectorStatus,
@@ -30,6 +31,7 @@ import { OCPPError } from '../../../exception/index.js'
 import {
   type ChangeConfigurationRequest,
   type ChangeConfigurationResponse,
+  type ClearCacheResponse,
   ConfigurationSection,
   ErrorType,
   type GenericResponse,
@@ -109,6 +111,7 @@ import {
   logger,
   sleep,
 } from '../../../utils/index.js'
+import { OCPPConstants } from '../OCPPConstants.js'
 import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService.js'
 import { OCPPServiceUtils } from '../OCPPServiceUtils.js'
 import { OCPP16Constants } from './OCPP16Constants.js'
@@ -175,7 +178,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       ],
       [
         OCPP16IncomingRequestCommand.CLEAR_CACHE,
-        super.handleRequestClearCache.bind(this) as unknown as IncomingRequestHandler,
+        this.handleRequestClearCache.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
@@ -699,6 +702,14 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     return OCPP16Constants.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
   }
 
+  private handleRequestClearCache (chargingStation: ChargingStation): ClearCacheResponse {
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    if (chargingStation.idTagsCache.deleteIdTags(getIdTagsFile(chargingStation.stationInfo!)!)) {
+      return OCPPConstants.OCPP_RESPONSE_ACCEPTED
+    }
+    return OCPPConstants.OCPP_RESPONSE_REJECTED
+  }
+
   private handleRequestClearChargingProfile (
     chargingStation: ChargingStation,
     commandPayload: OCPP16ClearChargingProfileRequest
index 5a1b8d9ebeab00578aaab7654eb3e159e78a53e9..3d99275e1907bd241d7319848aa9d78259c48a4d 100644 (file)
@@ -2,17 +2,11 @@ import _Ajv, { type ValidateFunction } from 'ajv'
 import _ajvFormats from 'ajv-formats'
 import { EventEmitter } from 'node:events'
 
-import type {
-  ClearCacheResponse,
-  IncomingRequestCommand,
-  JsonType,
-  OCPPVersion,
-} from '../../types/index.js'
+import type { IncomingRequestCommand, JsonType, OCPPVersion } from '../../types/index.js'
 
-import { type ChargingStation, getIdTagsFile } from '../../charging-station/index.js'
+import { type ChargingStation } from '../../charging-station/index.js'
 import { OCPPError } from '../../exception/index.js'
 import { logger } from '../../utils/index.js'
-import { OCPPConstants } from './OCPPConstants.js'
 import { ajvErrorsToErrorType } from './OCPPServiceUtils.js'
 
 type Ajv = _Ajv.default
@@ -58,17 +52,6 @@ export abstract class OCPPIncomingRequestService extends EventEmitter {
   ): Promise<void>
 
   public abstract stop (chargingStation: ChargingStation): void
-
-  protected handleRequestClearCache (
-    chargingStation: ChargingStation
-  ): ClearCacheResponse | Promise<ClearCacheResponse> {
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    if (chargingStation.idTagsCache.deleteIdTags(getIdTagsFile(chargingStation.stationInfo!)!)) {
-      return OCPPConstants.OCPP_RESPONSE_ACCEPTED
-    }
-    return OCPPConstants.OCPP_RESPONSE_REJECTED
-  }
-
   /**
    * Validates incoming request payload against JSON schema
    * @param chargingStation - The charging station instance processing the request