From: Jérôme Benoit Date: Fri, 28 Apr 2023 13:52:38 +0000 (+0200) Subject: refactor: factor out connector phase rotation value building X-Git-Tag: v1.2.12~51 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=dd08d43db9ea82b12b64289c68cb88ed6865b4de;p=e-mobility-charging-stations-simulator.git refactor: factor out connector phase rotation value building Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 159a1adb..22d554d1 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1197,42 +1197,26 @@ export class ChargingStation { StandardParametersKey.ConnectorPhaseRotation ) ) { - const connectorPhaseRotation = []; + const connectorsPhaseRotation: string[] = []; if (this.hasEvses) { for (const evseStatus of this.evses.values()) { for (const connectorId of evseStatus.connectors.keys()) { - // AC/DC - if (connectorId === 0 && this.getNumberOfPhases() === 0) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`); - } else if (connectorId > 0 && this.getNumberOfPhases() === 0) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`); - // AC - } else if (connectorId > 0 && this.getNumberOfPhases() === 1) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`); - } else if (connectorId > 0 && this.getNumberOfPhases() === 3) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`); - } + connectorsPhaseRotation.push( + ChargingStationUtils.getPhaseRotationValue(connectorId, this.getNumberOfPhases()) + ); } } } else { for (const connectorId of this.connectors.keys()) { - // AC/DC - if (connectorId === 0 && this.getNumberOfPhases() === 0) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`); - } else if (connectorId > 0 && this.getNumberOfPhases() === 0) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`); - // AC - } else if (connectorId > 0 && this.getNumberOfPhases() === 1) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`); - } else if (connectorId > 0 && this.getNumberOfPhases() === 3) { - connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`); - } + connectorsPhaseRotation.push( + ChargingStationUtils.getPhaseRotationValue(connectorId, this.getNumberOfPhases()) + ); } } ChargingStationConfigurationUtils.addConfigurationKey( this, StandardParametersKey.ConnectorPhaseRotation, - connectorPhaseRotation.toString() + connectorsPhaseRotation.toString() ); } if ( diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 4564f389..b1eb2591 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -18,6 +18,7 @@ import { type ChargingSchedulePeriod, type ChargingStationInfo, type ChargingStationTemplate, + ConnectorPhaseRotation, type ConnectorStatus, ConnectorStatusEnum, CurrentType, @@ -96,6 +97,20 @@ export class ChargingStationUtils { return true; } + public static getPhaseRotationValue(connectorId: number, numberOfPhases: number): string { + // AC/DC + if (connectorId === 0 && numberOfPhases === 0) { + return `${connectorId}.${ConnectorPhaseRotation.RST}`; + } else if (connectorId > 0 && numberOfPhases === 0) { + return `${connectorId}.${ConnectorPhaseRotation.NotApplicable}`; + // AC + } else if (connectorId > 0 && numberOfPhases === 1) { + return `${connectorId}.${ConnectorPhaseRotation.NotApplicable}`; + } else if (connectorId > 0 && numberOfPhases === 3) { + return `${connectorId}.${ConnectorPhaseRotation.RST}`; + } + } + public static getMaxNumberOfEvses(evses: Record): number { if (!evses) { return -1;