Simplify stop transaction payload handling
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Sep 2022 01:25:15 +0000 (03:25 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Sep 2022 01:25:15 +0000 (03:25 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/types/ocpp/1.6/Transaction.ts

index b6628cd73ac63f0f0e2c0c1d4cd1ea5d54772e28..bbe294b62ca07c7ed53292871829bd5dd9ee244d 100644 (file)
@@ -750,7 +750,6 @@ export default class ChargingStation {
       {
         transactionId,
         meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true),
-        idTag: this.getTransactionIdTag(transactionId),
         reason,
       }
     );
index ebc100990c943fae4abeb804760292258b8ee409..dfb50ab1dd67d318f251ed88a953aae67011e276 100644 (file)
@@ -142,8 +142,8 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
             requestPayload.transactionId,
             true
           ),
-          idTag: this.chargingStation.getTransactionIdTag(requestPayload.transactionId),
-          ...(requestPayload.reason && { reason: requestPayload.reason }),
+          idTag: requestPayload.idTag,
+          reason: requestPayload.reason,
         });
       case BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR:
         this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds);
index 7e4cc87720f81e10dacb625c00ed1474a821260d..650a8b9e77905aa7049ce292b609762b4b7b5f4b 100644 (file)
@@ -58,7 +58,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan
   private buildResponsePayload(uuid: string): ResponsePayload {
     const responsesStatus = this.responses
       .get(uuid)
-      ?.responses.every((response) => response.status === ResponseStatus.SUCCESS)
+      ?.responses.every(({ status }) => status === ResponseStatus.SUCCESS)
       ? ResponseStatus.SUCCESS
       : ResponseStatus.FAILURE;
     return {
index 4fa0190e84224464f92b8d2e4cda4cb35bc68b7a..fef9d86daa6cbe3a855b8e9c3d09b27584ae9eee 100644 (file)
@@ -179,6 +179,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
     commandParams?: JsonType
   ): Request {
     let connectorId: number;
+    let energyActiveImportRegister: number;
     commandParams = commandParams as JsonObject;
     switch (commandName) {
       case OCPP16RequestCommand.AUTHORIZE:
@@ -242,19 +243,25 @@ export default class OCPP16RequestService extends OCPPRequestService {
         connectorId = chargingStation.getConnectorIdByTransactionId(
           commandParams?.transactionId as number
         );
+        energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
+          commandParams?.transactionId as number,
+          true
+        );
         return {
           transactionId: commandParams?.transactionId,
-          ...(!Utils.isUndefined(commandParams?.idTag) && { idTag: commandParams.idTag }),
-          meterStop: commandParams?.meterStop,
+          idTag:
+            commandParams?.idTag ??
+            chargingStation.getTransactionIdTag(commandParams?.transactionId as number),
+          meterStop: commandParams?.meterStop ?? energyActiveImportRegister,
           timestamp: new Date().toISOString(),
-          ...(commandParams?.reason && { reason: commandParams.reason }),
+          reason: commandParams?.reason,
           ...(chargingStation.getTransactionDataMeterValues() && {
             transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
               chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
               OCPP16ServiceUtils.buildTransactionEndMeterValue(
                 chargingStation,
                 connectorId,
-                commandParams?.meterStop as number
+                (commandParams?.meterStop as number) ?? energyActiveImportRegister
               )
             ),
           }),
index ca68117d5020c04e3a556e7b58ed4940bdc23e52..14f9223c3c0d98188ded3b54f0492e0c849726cf 100644 (file)
@@ -42,8 +42,8 @@ export interface OCPP16StartTransactionRequest extends JsonObject {
   connectorId: number;
   idTag: string;
   meterStart: number;
-  reservationId?: number;
   timestamp: string;
+  reservationId?: number;
 }
 
 export interface OCPP16StartTransactionResponse extends JsonObject {