refactor: add type parameter to OCPP stack for request and response
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index 6e58309546f82caeec20b64a5b54223855940a0e..eaa84704f77621c92050e5c0f23b3d2fe13672a3 100644 (file)
@@ -305,13 +305,13 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     ) => boolean;
   }
 
-  public async incomingRequestHandler(
+  public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
     chargingStation: ChargingStation,
     messageId: string,
     commandName: OCPP16IncomingRequestCommand,
-    commandPayload: JsonType,
+    commandPayload: ReqType,
   ): Promise<void> {
-    let response: JsonType;
+    let response: ResType;
     if (
       chargingStation.getOcppStrictCompliance() === true &&
       chargingStation.inPendingState() === true &&
@@ -341,10 +341,10 @@ export class OCPP16IncomingRequestService 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(