Add missing OCPP 1.6 command payload JSON schemas
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPIncomingRequestService.ts
index 280a812ddc14b99d80a735a7dfbf4ffeaf6f4203..6015d4d9b8037956e1434ae23b934fd4f98bad6e 100644 (file)
@@ -1,12 +1,12 @@
 import { AsyncResource } from 'async_hooks';
 
-import type { JSONSchemaType } from 'ajv';
-import Ajv from 'ajv-draft-04';
+import Ajv, { type JSONSchemaType } from 'ajv';
 import ajvFormats from 'ajv-formats';
 
 import OCPPError from '../../exception/OCPPError';
 import type { HandleErrorParams } from '../../types/Error';
 import type { JsonType } from '../../types/JsonType';
+import type { OCPPVersion } from '../../types/ocpp/OCPPVersion';
 import type { IncomingRequestCommand } from '../../types/ocpp/Requests';
 import logger from '../../utils/Logger';
 import type ChargingStation from '../ChargingStation';
@@ -17,12 +17,14 @@ const moduleName = 'OCPPIncomingRequestService';
 export default abstract class OCPPIncomingRequestService {
   private static instance: OCPPIncomingRequestService | null = null;
   protected asyncResource: AsyncResource;
+  private readonly version: OCPPVersion;
   private readonly ajv: Ajv;
 
-  protected constructor() {
-    this.asyncResource = new AsyncResource(moduleName);
+  protected constructor(version: OCPPVersion) {
+    this.version = version;
     this.ajv = new Ajv();
     ajvFormats(this.ajv);
+    this.asyncResource = new AsyncResource(moduleName);
     this.incomingRequestHandler.bind(this);
     this.validateIncomingRequestPayload.bind(this);
   }
@@ -39,7 +41,7 @@ export default abstract class OCPPIncomingRequestService {
     commandName: IncomingRequestCommand,
     error: Error,
     params: HandleErrorParams<T> = { throwError: true }
-  ): T {
+  ): T | undefined {
     logger.error(
       `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
       error