refactor: cleanup reservation code helpers
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 31 Jul 2023 22:02:34 +0000 (00:02 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 31 Jul 2023 22:02:34 +0000 (00:02 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts

index 5f4f58b4ca86ea224ead2612b1d44c8d5282ab83..d08079c805760799b7e47d0f9c82dafc8bd7935a 100644 (file)
@@ -419,7 +419,7 @@ export class ChargingStation {
   }
 
   public getNumberOfRunningTransactions(): number {
-    let trxCount = 0;
+    let numberOfRunningTransactions = 0;
     if (this.hasEvses) {
       for (const [evseId, evseStatus] of this.evses) {
         if (evseId === 0) {
@@ -427,18 +427,18 @@ export class ChargingStation {
         }
         for (const connectorStatus of evseStatus.connectors.values()) {
           if (connectorStatus.transactionStarted === true) {
-            ++trxCount;
+            ++numberOfRunningTransactions;
           }
         }
       }
     } else {
       for (const connectorId of this.connectors.keys()) {
         if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) {
-          ++trxCount;
+          ++numberOfRunningTransactions;
         }
       }
     }
-    return trxCount;
+    return numberOfRunningTransactions;
   }
 
   public getOutOfOrderEndMeterValues(): boolean {
@@ -1074,15 +1074,14 @@ export class ChargingStation {
   }
 
   private getNumberOfReservationsOnConnectorZero(): number {
-    let numberOfReservations = 0;
     if (
       // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
       (this.hasEvses && this.evses.get(0)?.connectors.get(0)?.reservation) ||
       (!this.hasEvses && this.connectors.get(0)?.reservation)
     ) {
-      ++numberOfReservations;
+      return 1;
     }
-    return numberOfReservations;
+    return 0;
   }
 
   private flushMessageBuffer(): void {
index d2b1b926bdf8e4bfb51610b8d71e75f81eef69ec..6d2742517fdd387ddbf40da631ddfb4616375473 100644 (file)
@@ -118,16 +118,16 @@ export const removeExpiredReservations = async (
 export const getNumberOfReservableConnectors = (
   connectors: Map<number, ConnectorStatus>,
 ): number => {
-  let reservableConnectors = 0;
+  let numberOfReservableConnectors = 0;
   for (const [connectorId, connectorStatus] of connectors) {
     if (connectorId === 0) {
       continue;
     }
     if (connectorStatus.status === ConnectorStatusEnum.Available) {
-      ++reservableConnectors;
+      ++numberOfReservableConnectors;
     }
   }
-  return reservableConnectors;
+  return numberOfReservableConnectors;
 };
 
 export const getHashId = (index: number, stationTemplate: ChargingStationTemplate): string => {
@@ -257,7 +257,7 @@ export const checkConnectorsConfiguration = (
   templateMaxConnectors: number;
   templateMaxAvailableConnectors: number;
 } => {
-  const configuredMaxConnectors = getConfiguredNumberOfConnectors(stationTemplate);
+  const configuredMaxConnectors = getConfiguredMaxNumberOfConnectors(stationTemplate);
   checkConfiguredMaxConnectors(configuredMaxConnectors, logPrefix, templateFile);
   const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors!);
   checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile);
@@ -622,16 +622,16 @@ export const waitChargingStationEvents = async (
   });
 };
 
-const getConfiguredNumberOfConnectors = (stationTemplate: ChargingStationTemplate): number => {
-  let configuredMaxConnectors = 0;
+const getConfiguredMaxNumberOfConnectors = (stationTemplate: ChargingStationTemplate): number => {
+  let configuredMaxNumberOfConnectors = 0;
   if (isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {
     const numberOfConnectors = stationTemplate.numberOfConnectors as number[];
-    configuredMaxConnectors =
+    configuredMaxNumberOfConnectors =
       numberOfConnectors[Math.floor(secureRandom() * numberOfConnectors.length)];
   } else if (isUndefined(stationTemplate.numberOfConnectors) === false) {
-    configuredMaxConnectors = stationTemplate.numberOfConnectors as number;
+    configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number;
   } else if (stationTemplate.Connectors && !stationTemplate.Evses) {
-    configuredMaxConnectors = stationTemplate.Connectors[0]
+    configuredMaxNumberOfConnectors = stationTemplate.Connectors[0]
       ? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1
       : getMaxNumberOfConnectors(stationTemplate.Connectors);
   } else if (stationTemplate.Evses && !stationTemplate.Connectors) {
@@ -639,10 +639,12 @@ const getConfiguredNumberOfConnectors = (stationTemplate: ChargingStationTemplat
       if (evse === '0') {
         continue;
       }
-      configuredMaxConnectors += getMaxNumberOfConnectors(stationTemplate.Evses[evse].Connectors);
+      configuredMaxNumberOfConnectors += getMaxNumberOfConnectors(
+        stationTemplate.Evses[evse].Connectors,
+      );
     }
   }
-  return configuredMaxConnectors;
+  return configuredMaxNumberOfConnectors;
 };
 
 const checkConfiguredMaxConnectors = (