From 488fd3a755df336223b6d469a07c7605d325289b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 24 Oct 2020 00:07:25 +0200 Subject: [PATCH] Fixes to connectors initializing handling. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../station-templates/abb.station-template.json | 1 + src/charging-station/ChargingStation.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/assets/station-templates/abb.station-template.json b/src/assets/station-templates/abb.station-template.json index f0da9b4b..b5f86e59 100644 --- a/src/assets/station-templates/abb.station-template.json +++ b/src/assets/station-templates/abb.station-template.json @@ -11,6 +11,7 @@ "useConnectorId0": false, "randomConnectors": false, "resetTime": "30", + "enableStatistics": false, "Configuration": { "configurationKey": [ { diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index 39af7c7f..304a4e7a 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -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; } -- 2.34.1