refactor: remove unneeded connector 0 handling at connectors init
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 11:24:53 +0000 (13:24 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 11:24:53 +0000 (13:24 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts

index 0d7f286532425e708632a8ea80f632c54d3a53e5..6ea862e75030f40c6a9eee751e178b7ed1febc50 100644 (file)
@@ -1324,22 +1324,6 @@ export class ChargingStation {
       if (this.connectors?.size === 0 || connectorsConfigChanged) {
         connectorsConfigChanged && this.connectors.clear();
         this.connectorsConfigurationHash = connectorsConfigHash;
-        const connectorZeroStatus = stationInfo?.Connectors[0];
-        // Add connector id 0
-        if (connectorZeroStatus && this.getUseConnectorId0(stationInfo) === true) {
-          ChargingStationUtils.checkStationInfoConnectorStatus(
-            0,
-            connectorZeroStatus,
-            this.logPrefix(),
-            this.templateFile
-          );
-          this.connectors.set(0, Utils.cloneObject<ConnectorStatus>(connectorZeroStatus));
-          this.getConnectorStatus(0).availability = AvailabilityType.Operative;
-          if (Utils.isUndefined(this.getConnectorStatus(0)?.chargingProfiles)) {
-            this.getConnectorStatus(0).chargingProfiles = [];
-          }
-        }
-        // Add remaining connectors
         const templateMaxConnectors = ChargingStationUtils.getMaxNumberOfConnectors(
           stationInfo.Connectors
         );
@@ -1348,9 +1332,11 @@ export class ChargingStation {
           this.templateFile,
           this.logPrefix()
         );
+        const templateMaxAvailableConnectors = stationInfo?.Connectors[0]
+          ? templateMaxConnectors - 1
+          : templateMaxConnectors;
         if (
-          configuredMaxConnectors >
-            (stationInfo?.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) &&
+          configuredMaxConnectors > templateMaxAvailableConnectors &&
           !stationInfo?.randomConnectors
         ) {
           logger.warn(
@@ -1360,14 +1346,19 @@ export class ChargingStation {
           );
           stationInfo.randomConnectors = true;
         }
-        const templateMaxAvailableConnectors = stationInfo?.Connectors[0]
-          ? templateMaxConnectors - 1
-          : templateMaxConnectors;
-        if (templateMaxAvailableConnectors > 0) {
-          for (let connectorId = 1; connectorId <= configuredMaxConnectors; connectorId++) {
-            const templateConnectorId = stationInfo?.randomConnectors
-              ? Utils.getRandomInteger(templateMaxAvailableConnectors, 1)
-              : connectorId;
+        if (templateMaxConnectors > 0) {
+          for (let connectorId = 0; connectorId <= configuredMaxConnectors; connectorId++) {
+            if (
+              connectorId === 0 &&
+              (!stationInfo?.Connectors[connectorId] ||
+                this.getUseConnectorId0(stationInfo) === false)
+            ) {
+              continue;
+            }
+            const templateConnectorId =
+              connectorId > 0 && stationInfo?.randomConnectors
+                ? Utils.getRandomInteger(templateMaxAvailableConnectors, 1)
+                : connectorId;
             const connectorStatus = stationInfo?.Connectors[templateConnectorId];
             ChargingStationUtils.checkStationInfoConnectorStatus(
               templateConnectorId,
index 368471074b2f5d46642072e0eb2629d198dac00a..a14d20481950884b3c241e4ff0a0ee7f782604a7 100644 (file)
@@ -210,7 +210,7 @@ export class ChargingStationUtils {
     for (const connectorId of connectors.keys()) {
       if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) {
         logger.warn(
-          `${logPrefix} Connector ${connectorId} at initialization has a transaction started: ${
+          `${logPrefix} Connector id ${connectorId} at initialization has a transaction started: ${
             connectors.get(connectorId)?.transactionId
           }`
         );