From: Jérôme Benoit Date: Mon, 6 Mar 2023 12:22:47 +0000 (+0100) Subject: refactor(simulator): factor out supervision urls distribution X-Git-Tag: v1.1.95~22 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a52a644657916a3516798cbe8877a634ff8d6132;p=e-mobility-charging-stations-simulator.git refactor(simulator): factor out supervision urls distribution Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 5b260cb6..591b4644 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1937,24 +1937,22 @@ export class ChargingStation { const supervisionUrls = this.stationInfo?.supervisionUrls ?? Configuration.getSupervisionUrls(); if (Utils.isNotEmptyArray(supervisionUrls)) { switch (Configuration.getSupervisionUrlDistribution()) { - case SupervisionUrlDistribution.ROUND_ROBIN: - // FIXME - this.configuredSupervisionUrlIndex = (this.index - 1) % supervisionUrls.length; - break; case SupervisionUrlDistribution.RANDOM: this.configuredSupervisionUrlIndex = Math.floor( Utils.secureRandom() * supervisionUrls.length ); break; + case SupervisionUrlDistribution.ROUND_ROBIN: case SupervisionUrlDistribution.CHARGING_STATION_AFFINITY: - this.configuredSupervisionUrlIndex = (this.index - 1) % supervisionUrls.length; - break; default: - logger.error( - `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${ - SupervisionUrlDistribution.CHARGING_STATION_AFFINITY - }` - ); + Object.values(SupervisionUrlDistribution).includes( + Configuration.getSupervisionUrlDistribution() + ) === false && + logger.error( + `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${ + SupervisionUrlDistribution.CHARGING_STATION_AFFINITY + }` + ); this.configuredSupervisionUrlIndex = (this.index - 1) % supervisionUrls.length; break; }