fix: ensure undefined is handled at computing power limitation
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Nov 2024 12:54:23 +0000 (13:54 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Nov 2024 12:54:23 +0000 (13:54 +0100)
closes #1223

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts
ui/web/src/composables/Utils.ts

index 45a2f94edc15e053d8156af70581cb1ac7fe60ba..ed7449a9d2d884a1ec2ed5cbf95fd1a0064a3c60 100644 (file)
@@ -419,19 +419,15 @@ export class ChargingStation extends EventEmitter {
     const connectorChargingProfilesLimit = getConnectorChargingProfilesLimit(this, connectorId)
     return min(
       Number.isNaN(connectorMaximumPower) ? Number.POSITIVE_INFINITY : connectorMaximumPower,
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      Number.isNaN(connectorAmperageLimitationLimit!)
+      connectorAmperageLimitationLimit == null || Number.isNaN(connectorAmperageLimitationLimit)
         ? Number.POSITIVE_INFINITY
-        : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        connectorAmperageLimitationLimit!,
+        : connectorAmperageLimitationLimit,
       Number.isNaN(chargingStationChargingProfilesLimit)
         ? Number.POSITIVE_INFINITY
         : chargingStationChargingProfilesLimit,
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      Number.isNaN(connectorChargingProfilesLimit!)
+      connectorChargingProfilesLimit == null || Number.isNaN(connectorChargingProfilesLimit)
         ? Number.POSITIVE_INFINITY
-        : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        connectorChargingProfilesLimit!
+        : connectorChargingProfilesLimit
     )
   }
 
index 5fcc40935ea8846512869585b6dfb6aa3790bf76..d34749e4b2f4857042940911b14b55c76c56a52e 100644 (file)
@@ -29,7 +29,7 @@ export const convertToInt = (value: unknown): number => {
   if (typeof value === 'string') {
     changedValue = Number.parseInt(value)
   }
-  if (isNaN(changedValue)) {
+  if (Number.isNaN(changedValue)) {
     // eslint-disable-next-line @typescript-eslint/no-base-to-string
     throw new Error(`Cannot convert to integer: '${value.toString()}'`)
   }