Fixes to connectors initializing handling.
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 23 Oct 2020 22:07:25 +0000 (00:07 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 23 Oct 2020 22:07:25 +0000 (00:07 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/station-templates/abb.station-template.json
src/charging-station/ChargingStation.js

index f0da9b4b7fb8933b275d5a9cc8d2a70f6d731571..b5f86e59078f2c3023abe48128826afa20c36dd1 100644 (file)
@@ -11,6 +11,7 @@
   "useConnectorId0": false,
   "randomConnectors": false,
   "resetTime": "30",
+  "enableStatistics": false,
   "Configuration": {
     "configurationKey": [
       {
index 39af7c7f7959b47f6df7e6a110ec7b08a0fa9554..304a4e7abd6af4efd13bfd7fd9f28f9d906b4aca 100644 (file)
@@ -68,7 +68,7 @@ class ChargingStation {
     // Build connectors if needed
     const maxConnectors = this._getMaxNumberOfConnectors();
     if (maxConnectors <= 0) {
-      const errMsg = `${this._logPrefix()} Charging station template with no connectors`;
+      const errMsg = `${this._logPrefix()} Charging station template ${this._stationTemplateFile} with no connectors`;
       logger.error(errMsg);
       throw Error(errMsg);
     }
@@ -80,8 +80,8 @@ class ChargingStation {
       let lastConnector;
       for (lastConnector in this._stationInfo.Connectors) {
         // Add connector Id 0
-        if (Utils.convertToBoolean(this._stationInfo.useConnectorId0) && Utils.convertToInt(lastConnector) === 0 &&
-        this._stationInfo.Connectors[lastConnector]) {
+        if (Utils.convertToBoolean(this._stationInfo.useConnectorId0) && this._stationInfo.Connectors[lastConnector] &&
+          lastConnector === 0) {
           this._connectors[lastConnector] = Utils.cloneJSonDocument(this._stationInfo.Connectors[lastConnector]);
         }
       }
@@ -89,6 +89,11 @@ class ChargingStation {
       if (!this._getConfigurationKey('MeterValuesSampledData')) {
         this._addConfigurationKey('MeterValuesSampledData', 'Energy.Active.Import.Register');
       }
+      // Sanity check
+      if (maxConnectors > lastConnector && !Utils.convertToBoolean(this._stationInfo.randomConnectors)) {
+        logger.warn(`${this._logPrefix()} Number of connectors exceeds the number of connector configurations in template ${this._stationTemplateFile}, forcing random connector configurations affectation`);
+        this._stationInfo.randomConnectors = true;
+      }
       // Generate all connectors
       for (let index = 1; index <= maxConnectors; index++) {
         const randConnectorID = Utils.convertToBoolean(this._stationInfo.randomConnectors) ? Utils.getRandomInt(lastConnector, 1) : index;
@@ -186,8 +191,11 @@ class ChargingStation {
     if (!Utils.isEmptyArray(this._stationInfo.numberOfConnectors)) {
       // Distribute evenly the number of connectors
       maxConnectors = this._stationInfo.numberOfConnectors[(this._index - 1) % this._stationInfo.numberOfConnectors.length];
-    } else {
+    } else if (this._stationInfo.numberOfConnectors) {
       maxConnectors = this._stationInfo.numberOfConnectors;
+    } else {
+      maxConnectors = Utils.convertToBoolean(this._stationInfo.useConnectorId0) ? Object.keys(this._stationInfo.Connectors).length - 1 :
+                                              Object.keys(this._stationInfo.Connectors).length;
     }
     return maxConnectors;
   }