]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix: replace incorrect zero fallbacks for maximumPower and maximumAmperage
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Mar 2026 19:10:32 +0000 (20:10 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Mar 2026 19:10:32 +0000 (20:10 +0100)
Station physical properties (maximumPower, maximumAmperage) are validated
> 0 at startup. Using ?? 0 as fallback silently produces invalid states:
0W power limits blocking all charging, 0A amperage in config keys.

Replace with proper null guards that log errors and fail-open:
- getConnectorMaximumAvailablePower: return Infinity (no limit known)
- getMaximumAmperage: return undefined (caller already handles it)
- initializeOcppConfiguration: skip config key, log error
- getChargingStationChargingProfilesLimit: return limit uncapped
- getConnectorChargingProfilesLimit: return limit uncapped

src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts

index 4a59aac326ffa985c87de87f4f6138dbe465438b..d2049f4038df0b8c420f1c346a2fbdbf3ffae707 100644 (file)
@@ -504,7 +504,16 @@ export class ChargingStation extends EventEmitter {
           )
           : DCElectricUtils.power(voltageOut, amperageLimitation)) / (this.powerDivider ?? 1)
     }
-    const connectorMaximumPower = (this.stationInfo?.maximumPower ?? 0) / (this.powerDivider ?? 1)
+    const maximumPower = this.stationInfo?.maximumPower
+    if (maximumPower == null || maximumPower <= 0) {
+      logger.error(
+        `${this.logPrefix()} getConnectorMaximumAvailablePower: maximumPower is ${
+          maximumPower?.toString() ?? 'undefined'
+        }, cannot compute connector maximum power`
+      )
+      return Number.POSITIVE_INFINITY
+    }
+    const connectorMaximumPower = maximumPower / (this.powerDivider ?? 1)
     const chargingStationChargingProfilesLimit =
       (getChargingStationChargingProfilesLimit(this) ?? Number.POSITIVE_INFINITY) /
       (this.powerDivider ?? 1)
@@ -1443,7 +1452,15 @@ export class ChargingStation extends EventEmitter {
 
   private getMaximumAmperage (stationInfo?: ChargingStationInfo): number | undefined {
     const localStationInfo = stationInfo ?? this.stationInfo
-    const maximumPower = localStationInfo?.maximumPower ?? 0
+    const maximumPower = localStationInfo?.maximumPower
+    if (maximumPower == null || maximumPower <= 0) {
+      logger.error(
+        `${this.logPrefix()} getMaximumAmperage: maximumPower is ${
+          maximumPower?.toString() ?? 'undefined'
+        }, cannot compute maximum amperage`
+      )
+      return undefined
+    }
     switch (this.getCurrentOutType(stationInfo)) {
       case CurrentType.AC:
         return ACElectricUtils.amperagePerPhaseFromPower(
@@ -2062,12 +2079,21 @@ export class ChargingStation extends EventEmitter {
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
       getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey) == null
     ) {
-      addConfigurationKey(
-        this,
-        this.stationInfo.amperageLimitationOcppKey,
-        // prettier-ignore
-        ((this.stationInfo.maximumAmperage ?? 0) * getAmperageLimitationUnitDivider(this.stationInfo)).toString()
-      )
+      const maximumAmperage = this.stationInfo.maximumAmperage
+      if (maximumAmperage != null && maximumAmperage > 0) {
+        addConfigurationKey(
+          this,
+          this.stationInfo.amperageLimitationOcppKey,
+          // prettier-ignore
+          (maximumAmperage * getAmperageLimitationUnitDivider(this.stationInfo)).toString()
+        )
+      } else {
+        logger.error(
+          `${this.logPrefix()} initializeOcppConfiguration: maximumAmperage is ${
+            maximumAmperage?.toString() ?? 'undefined'
+          }, cannot set amperage limitation configuration key`
+        )
+      }
     }
     if (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) {
       addConfigurationKey(
index d3ffaaceb21b114e0cc024d85b166096b5eaa124..f2c1c9f5548eb7eca2769148e4c4159a17c95bc8 100644 (file)
@@ -788,7 +788,10 @@ export const getChargingStationChargingProfilesLimit = (
     const chargingProfilesLimit = getChargingProfilesLimit(chargingStation, 0, chargingProfiles)
     if (chargingProfilesLimit != null) {
       const limit = buildChargingProfilesLimit(chargingStation, chargingProfilesLimit)
-      const chargingStationMaximumPower = chargingStation.stationInfo?.maximumPower ?? 0
+      const chargingStationMaximumPower = chargingStation.stationInfo?.maximumPower
+      if (chargingStationMaximumPower == null) {
+        return limit
+      }
       if (limit > chargingStationMaximumPower) {
         logger.error(
           `${chargingStation.logPrefix()} ${moduleName}.getChargingStationChargingProfilesLimit: Charging profile id ${getChargingProfileId(chargingProfilesLimit.chargingProfile)} limit ${limit.toString()} is greater than charging station maximum ${chargingStationMaximumPower.toString()}: %j`,
@@ -851,8 +854,11 @@ export const getConnectorChargingProfilesLimit = (
     )
     if (chargingProfilesLimit != null) {
       const limit = buildChargingProfilesLimit(chargingStation, chargingProfilesLimit)
-      const connectorMaximumPower =
-        (chargingStation.stationInfo?.maximumPower ?? 0) / (chargingStation.powerDivider ?? 1)
+      const maximumPower = chargingStation.stationInfo?.maximumPower
+      if (maximumPower == null) {
+        return limit
+      }
+      const connectorMaximumPower = maximumPower / (chargingStation.powerDivider ?? 1)
       if (limit > connectorMaximumPower) {
         logger.error(
           `${chargingStation.logPrefix()} ${moduleName}.getConnectorChargingProfilesLimit: Charging profile id ${getChargingProfileId(chargingProfilesLimit.chargingProfile)} limit ${limit.toString()} is greater than connector ${connectorId.toString()} maximum ${connectorMaximumPower.toString()}: %j`,