refactor: factor out connector phase rotation value building
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 13:52:38 +0000 (15:52 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 13:52:38 +0000 (15:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts

index 159a1adb1ce5a8f5438b3a505a3b8ec3fddf4e29..22d554d1341dbcbe8bf5ec410e5a6071acd0dbd0 100644 (file)
@@ -1197,42 +1197,26 @@ export class ChargingStation {
         StandardParametersKey.ConnectorPhaseRotation
       )
     ) {
-      const connectorPhaseRotation = [];
+      const connectorsPhaseRotation: string[] = [];
       if (this.hasEvses) {
         for (const evseStatus of this.evses.values()) {
           for (const connectorId of evseStatus.connectors.keys()) {
-            // AC/DC
-            if (connectorId === 0 && this.getNumberOfPhases() === 0) {
-              connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
-            } else if (connectorId > 0 && this.getNumberOfPhases() === 0) {
-              connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
-              // AC
-            } else if (connectorId > 0 && this.getNumberOfPhases() === 1) {
-              connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
-            } else if (connectorId > 0 && this.getNumberOfPhases() === 3) {
-              connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
-            }
+            connectorsPhaseRotation.push(
+              ChargingStationUtils.getPhaseRotationValue(connectorId, this.getNumberOfPhases())
+            );
           }
         }
       } else {
         for (const connectorId of this.connectors.keys()) {
-          // AC/DC
-          if (connectorId === 0 && this.getNumberOfPhases() === 0) {
-            connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
-          } else if (connectorId > 0 && this.getNumberOfPhases() === 0) {
-            connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
-            // AC
-          } else if (connectorId > 0 && this.getNumberOfPhases() === 1) {
-            connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
-          } else if (connectorId > 0 && this.getNumberOfPhases() === 3) {
-            connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
-          }
+          connectorsPhaseRotation.push(
+            ChargingStationUtils.getPhaseRotationValue(connectorId, this.getNumberOfPhases())
+          );
         }
       }
       ChargingStationConfigurationUtils.addConfigurationKey(
         this,
         StandardParametersKey.ConnectorPhaseRotation,
-        connectorPhaseRotation.toString()
+        connectorsPhaseRotation.toString()
       );
     }
     if (
index 4564f389674f45e4dba051e2bf0432e8db11dafa..b1eb259156bceaa3b655e3ecd5000d4202bc73b9 100644 (file)
@@ -18,6 +18,7 @@ import {
   type ChargingSchedulePeriod,
   type ChargingStationInfo,
   type ChargingStationTemplate,
+  ConnectorPhaseRotation,
   type ConnectorStatus,
   ConnectorStatusEnum,
   CurrentType,
@@ -96,6 +97,20 @@ export class ChargingStationUtils {
     return true;
   }
 
+  public static getPhaseRotationValue(connectorId: number, numberOfPhases: number): string {
+    // AC/DC
+    if (connectorId === 0 && numberOfPhases === 0) {
+      return `${connectorId}.${ConnectorPhaseRotation.RST}`;
+    } else if (connectorId > 0 && numberOfPhases === 0) {
+      return `${connectorId}.${ConnectorPhaseRotation.NotApplicable}`;
+      // AC
+    } else if (connectorId > 0 && numberOfPhases === 1) {
+      return `${connectorId}.${ConnectorPhaseRotation.NotApplicable}`;
+    } else if (connectorId > 0 && numberOfPhases === 3) {
+      return `${connectorId}.${ConnectorPhaseRotation.RST}`;
+    }
+  }
+
   public static getMaxNumberOfEvses(evses: Record<string, EvseTemplate>): number {
     if (!evses) {
       return -1;