Add occpStrictCompliance template tunable
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16RequestService.ts
index 6ae6cf3225e208abba901fb3e560608b943f1158..3580cc52e18701ff05f8a6939b6714bb5be9113a 100644 (file)
@@ -8,6 +8,7 @@ import { MeterValueUnit, MeterValuesRequest, OCPP16MeterValue, OCPP16MeterValueM
 
 import Constants from '../../../utils/Constants';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
+import { JsonType } from '../../../types/JsonType';
 import MeasurandPerPhaseSampledValueTemplates from '../../../types/MeasurandPerPhaseSampledValueTemplates';
 import MeasurandValues from '../../../types/MeasurandValues';
 import { MessageType } from '../../../types/ocpp/MessageType';
@@ -106,7 +107,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
       }
       const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(this.chargingStation, connectorId, meterStop);
       // FIXME: should be a callback, each OCPP commands implementation must do only one job
-      (this.chargingStation.getBeginEndMeterValues() && !this.chargingStation.getOutOfOrderEndMeterValues())
+      (this.chargingStation.getBeginEndMeterValues() && this.chargingStation.getOcppStrictCompliance() && !this.chargingStation.getOutOfOrderEndMeterValues())
         && await this.sendTransactionEndMeterValues(connectorId, transactionId, transactionEndMeterValue);
       const payload: StopTransactionRequest = {
         transactionId,
@@ -381,21 +382,21 @@ export default class OCPP16RequestService extends OCPPRequestService {
     }
   }
 
-  public async sendResult(messageId: string, resultMessageData: Record<string, unknown>, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise<unknown> {
+  public async sendResult(messageId: string, resultMessageData: JsonType, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise<JsonType> {
     try {
       // Send error
-      return await this.sendMessage(messageId, resultMessageData, MessageType.CALL_RESULT_MESSAGE, commandName);
-    } catch (err) {
-      this.handleRequestError(commandName as OCPP16RequestCommand, err as Error);
+      return await this.sendMessage(messageId, resultMessageData, MessageType.CALL_RESULT_MESSAGE, commandName) as JsonType;
+    } catch (error) {
+      this.handleRequestError(commandName as OCPP16RequestCommand, error as Error);
     }
   }
 
-  public async sendError(messageId: string, error: OCPPError, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise<unknown> {
+  public async sendError(messageId: string, ocppError: OCPPError, commandName: OCPP16RequestCommand | OCPP16IncomingRequestCommand): Promise<JsonType> {
     try {
       // Send error
-      return await this.sendMessage(messageId, error, MessageType.CALL_ERROR_MESSAGE, commandName);
-    } catch (err) {
-      this.handleRequestError(commandName as OCPP16RequestCommand, err as Error);
+      return await this.sendMessage(messageId, ocppError, MessageType.CALL_ERROR_MESSAGE, commandName) as JsonType;
+    } catch (error) {
+      this.handleRequestError(commandName as OCPP16RequestCommand, error as Error);
     }
   }
 }