From dd08d43db9ea82b12b64289c68cb88ed6865b4de Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 Apr 2023 15:52:38 +0200 Subject: [PATCH] refactor: factor out connector phase rotation value building MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 32 +++++--------------- src/charging-station/ChargingStationUtils.ts | 15 +++++++++ 2 files changed, 23 insertions(+), 24 deletions(-) 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; -- 2.34.1