Fix docker image build
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index ebd77f83ac54a4d5303712ffcd69a5f78705e81c..a451c5ee4668b31cbad728fa4881cf2356a812a8 100644 (file)
@@ -255,29 +255,33 @@ export default class ChargingStation {
     return this.stationInfo.phaseLineToLineVoltageMeterValues ?? false;
   }
 
-  public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined {
-    if (this.getMeteringPerTransaction()) {
-      for (const connectorId of this.connectors.keys()) {
-        if (
-          connectorId > 0 &&
-          this.getConnectorStatus(connectorId).transactionId === transactionId
-        ) {
-          return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue;
-        }
-      }
-    }
+  public getConnectorIdByTransactionId(transactionId: number): number | undefined {
     for (const connectorId of this.connectors.keys()) {
-      if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
-        return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue;
+      if (
+        connectorId > 0 &&
+        this.getConnectorStatus(connectorId)?.transactionId === transactionId
+      ) {
+        return connectorId;
       }
     }
   }
 
+  public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined {
+    const transactionConnectorStatus = this.getConnectorStatus(
+      this.getConnectorIdByTransactionId(transactionId)
+    );
+    if (this.getMeteringPerTransaction()) {
+      return transactionConnectorStatus?.transactionEnergyActiveImportRegisterValue;
+    }
+    return transactionConnectorStatus?.energyActiveImportRegisterValue;
+  }
+
   public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number | undefined {
+    const connectorStatus = this.getConnectorStatus(connectorId);
     if (this.getMeteringPerTransaction()) {
-      return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue;
+      return connectorStatus?.transactionEnergyActiveImportRegisterValue;
     }
-    return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue;
+    return connectorStatus?.energyActiveImportRegisterValue;
   }
 
   public getAuthorizeRemoteTxRequests(): boolean {
@@ -653,14 +657,13 @@ export default class ChargingStation {
     // In case of multiple instances: add instance index to charging station id
     const instanceIndex = process.env.CF_INSTANCE_INDEX ?? 0;
     const idSuffix = stationTemplate.nameSuffix ?? '';
+    const idStr = '000000000' + this.index.toString();
     return stationTemplate.fixedName
       ? stationTemplate.baseName
       : stationTemplate.baseName +
           '-' +
           instanceIndex.toString() +
-          ('000000000' + this.index.toString()).substr(
-            ('000000000' + this.index.toString()).length - 4
-          ) +
+          idStr.substring(idStr.length - 4) +
           idSuffix;
   }
 
@@ -954,6 +957,11 @@ export default class ChargingStation {
             chargePointVendor: this.bootNotificationRequest.chargePointVendor,
             chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
             firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+            chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
+            iccid: this.bootNotificationRequest.iccid,
+            imsi: this.bootNotificationRequest.imsi,
+            meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
+            meterType: this.bootNotificationRequest.meterType,
           },
           { skipBufferingOnError: true }
         )) as BootNotificationResponse;
@@ -1258,6 +1266,11 @@ export default class ChargingStation {
           chargePointVendor: this.bootNotificationRequest.chargePointVendor,
           chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
           firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+          chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
+          iccid: this.bootNotificationRequest.iccid,
+          imsi: this.bootNotificationRequest.imsi,
+          meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
+          meterType: this.bootNotificationRequest.meterType,
         },
         { skipBufferingOnError: true }
       );