fix: ensure custom meterValues values are taken
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPResponseService.ts
index 46d12fb048aa7374972316451972a4090aef59a2..0aedbb1eebb5b6a17a2abe94b2b85641c68c07e9 100644 (file)
@@ -4,13 +4,7 @@ import ajvFormats from 'ajv-formats';
 import { OCPPServiceUtils } from './OCPPServiceUtils';
 import type { ChargingStation } from '../../charging-station';
 import { OCPPError } from '../../exception';
-import type {
-  IncomingRequestCommand,
-  JsonObject,
-  JsonType,
-  OCPPVersion,
-  RequestCommand,
-} from '../../types';
+import type { IncomingRequestCommand, JsonType, OCPPVersion, RequestCommand } from '../../types';
 import { logger } from '../../utils';
 
 const moduleName = 'OCPPResponseService';
@@ -20,16 +14,16 @@ export abstract class OCPPResponseService {
 
   public jsonIncomingRequestResponseValidateFunctions: Map<
     IncomingRequestCommand,
-    ValidateFunction<JsonObject>
+    ValidateFunction<JsonType>
   >;
 
   private readonly version: OCPPVersion;
   private readonly ajv: Ajv;
-  private jsonRequestValidateFunctions: Map<RequestCommand, ValidateFunction<JsonObject>>;
+  private jsonRequestValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>;
 
   public abstract jsonIncomingRequestResponseSchemas: Map<
     IncomingRequestCommand,
-    JSONSchemaType<JsonObject>
+    JSONSchemaType<JsonType>
   >;
 
   protected constructor(version: OCPPVersion) {
@@ -39,10 +33,10 @@ export abstract class OCPPResponseService {
       multipleOfPrecision: 2,
     });
     ajvFormats(this.ajv);
-    this.jsonRequestValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonObject>>();
+    this.jsonRequestValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonType>>();
     this.jsonIncomingRequestResponseValidateFunctions = new Map<
       IncomingRequestCommand,
-      ValidateFunction<JsonObject>
+      ValidateFunction<JsonType>
     >();
     this.responseHandler = this.responseHandler.bind(this) as <
       ReqType extends JsonType,
@@ -74,14 +68,11 @@ export abstract class OCPPResponseService {
     schema: JSONSchemaType<T>,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
     if (this.jsonRequestValidateFunctions.has(commandName) === false) {
-      this.jsonRequestValidateFunctions.set(
-        commandName,
-        this.ajv.compile<JsonObject>(schema).bind(this),
-      );
+      this.jsonRequestValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
     }
     const validate = this.jsonRequestValidateFunctions.get(commandName)!;
     if (validate(payload)) {
@@ -92,7 +83,7 @@ export abstract class OCPPResponseService {
       validate.errors,
     );
     throw new OCPPError(
-      OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+      OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
       'Response PDU is invalid',
       commandName,
       JSON.stringify(validate.errors, undefined, 2),