Only compute amperage limitation when needed
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 25 Mar 2022 11:27:47 +0000 (12:27 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 25 Mar 2022 11:27:47 +0000 (12:27 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 3051abb7065de6382b2ffd7f2ba6d88c9bb23685..40e2c1b1fbc27d1c6070e04f099bf5a858733a68 100644 (file)
@@ -236,9 +236,9 @@ export default class ChargingStation {
   }
 
   public getConnectorMaximumAvailablePower(connectorId: number): number {
-    let amperageLimitationPowerLimit: number;
+    let connectorAmperageLimitationPowerLimit: number;
     if (this.getAmperageLimitation() < this.stationInfo.maximumAmperage) {
-      amperageLimitationPowerLimit =
+      const amperageLimitationPowerLimit =
         this.getCurrentOutType() === CurrentType.AC
           ? ACElectricUtils.powerTotal(
               this.getNumberOfPhases(),
@@ -246,12 +246,12 @@ export default class ChargingStation {
               this.getAmperageLimitation() * this.getNumberOfConnectors()
             )
           : DCElectricUtils.power(this.getVoltageOut(), this.getAmperageLimitation());
+      connectorAmperageLimitationPowerLimit =
+        amperageLimitationPowerLimit / this.stationInfo.powerDivider;
     }
     const connectorMaximumPower =
       ((this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower) /
       this.stationInfo.powerDivider;
-    const connectorAmperageLimitationPowerLimit =
-      amperageLimitationPowerLimit / this.stationInfo.powerDivider;
     const connectorChargingProfilePowerLimit = this.getChargingProfilePowerLimit(connectorId);
     return Math.min(
       isNaN(connectorMaximumPower) ? Infinity : connectorMaximumPower,