From fe8423d156795bffd13c17a6711a80176f3bccc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 26 Feb 2026 06:45:13 +0100 Subject: [PATCH] refactor(ocpp): move ClearCache handler to OCPP 1.6 service Auth cache implementation differs between OCPP versions, so shared handler in parent class was not appropriate. --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 13 +++++++++++- .../ocpp/OCPPIncomingRequestService.ts | 21 ++----------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index bcb87fc6..9fe6c662 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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 diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 5a1b8d9e..3d99275e 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -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 public abstract stop (chargingStation: ChargingStation): void - - protected handleRequestClearCache ( - chargingStation: ChargingStation - ): ClearCacheResponse | Promise { - // 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 -- 2.53.0