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