From: Jérôme Benoit Date: Fri, 23 Oct 2020 22:07:25 +0000 (+0200) Subject: Fixes to connectors initializing handling. X-Git-Tag: v1.0.1-0~245 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=488fd3a755df336223b6d469a07c7605d325289b;hp=8bce55bf352af9b46f2285d8979948b8ec0adee0;p=e-mobility-charging-stations-simulator.git Fixes to connectors initializing handling. Signed-off-by: Jérôme Benoit --- 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; }