X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20IncomingRequestService.ts;h=0d657d99f7bd67b365660c3e2888653157485e5c;hb=1cee0015ac704be480535c7228103525cc3c8cc2;hp=6cfb4ec1374f1b76de353b6cb4b7546d75797fa5;hpb=5edd8ba0f8978cfb3ca9d80f299d9748c6c5970e;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 6cfb4ec1..0d657d99 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -8,7 +8,6 @@ import { OCPPError } from '../../../exception'; import { ErrorType, type IncomingRequestHandler, - type JsonObject, type JsonType, type OCPP20ClearCacheRequest, OCPP20IncomingRequestCommand, @@ -20,7 +19,7 @@ import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService'; const moduleName = 'OCPP20IncomingRequestService'; export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { - protected jsonSchemas: Map>; + protected jsonSchemas: Map>; private incomingRequestHandlers: Map; public constructor() { @@ -31,7 +30,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { this.incomingRequestHandlers = new Map([ [OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)], ]); - this.jsonSchemas = new Map>([ + this.jsonSchemas = new Map>([ [ OCPP20IncomingRequestCommand.CLEAR_CACHE, OCPP20ServiceUtils.parseJsonSchemaFile( @@ -48,15 +47,15 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ) => boolean; } - public async incomingRequestHandler( + public async incomingRequestHandler( chargingStation: ChargingStation, messageId: string, commandName: OCPP20IncomingRequestCommand, - commandPayload: JsonType, + commandPayload: ReqType, ): Promise { - let response: JsonType; + let response: ResType; if ( - chargingStation.getOcppStrictCompliance() === true && + chargingStation.stationInfo?.ocppStrictCompliance === true && chargingStation.inPendingState() === true && (commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION || commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION) @@ -65,7 +64,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is in pending state on the central server`, commandName, @@ -74,7 +73,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { } if ( chargingStation.isRegistered() === true || - (chargingStation.getOcppStrictCompliance() === false && + (chargingStation.stationInfo?.ocppStrictCompliance === false && chargingStation.inUnknownState() === true) ) { if ( @@ -84,10 +83,10 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { try { this.validatePayload(chargingStation, commandName, commandPayload); // Call the method to build the response - response = await this.incomingRequestHandlers.get(commandName)( + response = (await this.incomingRequestHandlers.get(commandName)!( chargingStation, commandPayload, - ); + )) as ResType; } catch (error) { // Log logger.error( @@ -102,7 +101,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )}`, commandName, @@ -114,7 +113,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request PDU ${JSON.stringify( commandPayload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, @@ -139,7 +138,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { return this.validateIncomingRequestPayload( chargingStation, commandName, - this.jsonSchemas.get(commandName), + this.jsonSchemas.get(commandName)!, commandPayload, ); }