From: Jérôme Benoit Date: Fri, 28 Apr 2023 11:24:53 +0000 (+0200) Subject: refactor: remove unneeded connector 0 handling at connectors init X-Git-Tag: v1.2.12~57 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=269196a85d9aaa72ccaba003dcfbac00794a9da7;p=e-mobility-charging-stations-simulator.git refactor: remove unneeded connector 0 handling at connectors init Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 0d7f2865..6ea862e7 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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(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, diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 36847107..a14d2048 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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 }` );