Combined PR (#197)
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index e6b9c17d53cb9c65bb3d37298983c8484db388d2..24556120b4b9db9862dfae478ce3fcb468e2a309 100644 (file)
@@ -109,16 +109,13 @@ export class ChargingStationUtils {
     }
   }
 
-  public static getConfiguredNumberOfConnectors(
-    index: number,
-    stationTemplate: ChargingStationTemplate
-  ): number {
+  public static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
     let configuredMaxConnectors: number;
-    if (!Utils.isEmptyArray(stationTemplate.numberOfConnectors)) {
+    if (Utils.isEmptyArray(stationTemplate.numberOfConnectors) === false) {
       const numberOfConnectors = stationTemplate.numberOfConnectors as number[];
-      // Distribute evenly the number of connectors
-      configuredMaxConnectors = numberOfConnectors[(index - 1) % numberOfConnectors.length];
-    } else if (!Utils.isUndefined(stationTemplate.numberOfConnectors)) {
+      configuredMaxConnectors =
+        numberOfConnectors[Math.floor(Utils.secureRandom() * numberOfConnectors.length)];
+    } else if (Utils.isUndefined(stationTemplate.numberOfConnectors) === false) {
       configuredMaxConnectors = stationTemplate.numberOfConnectors as number;
     } else {
       configuredMaxConnectors = stationTemplate?.Connectors[0]
@@ -417,7 +414,7 @@ export class ChargingStationUtils {
     phase?: MeterValuePhase
   ): SampledValueTemplate | undefined {
     const onPhaseStr = phase ? `on phase ${phase} ` : '';
-    if (!Constants.SUPPORTED_MEASURANDS.includes(measurand)) {
+    if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) {
       logger.warn(
         `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
       );
@@ -445,10 +442,10 @@ export class ChargingStationUtils {
       index++
     ) {
       if (
-        !Constants.SUPPORTED_MEASURANDS.includes(
+        Constants.SUPPORTED_MEASURANDS.includes(
           sampledValueTemplates[index]?.measurand ??
             MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-        )
+        ) === false
       ) {
         logger.warn(
           `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
@@ -460,7 +457,7 @@ export class ChargingStationUtils {
         ChargingStationConfigurationUtils.getConfigurationKey(
           chargingStation,
           StandardParametersKey.MeterValuesSampledData
-        )?.value.includes(measurand)
+        )?.value.includes(measurand) === true
       ) {
         return sampledValueTemplates[index];
       } else if (
@@ -470,7 +467,7 @@ export class ChargingStationUtils {
         ChargingStationConfigurationUtils.getConfigurationKey(
           chargingStation,
           StandardParametersKey.MeterValuesSampledData
-        )?.value.includes(measurand)
+        )?.value.includes(measurand) === true
       ) {
         return sampledValueTemplates[index];
       } else if (
@@ -507,9 +504,15 @@ export class ChargingStationUtils {
     chargingStation: ChargingStation
   ): boolean {
     const isRequestCommand = Object.values(RequestCommand).includes(command);
-    if (isRequestCommand && !chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
+    if (
+      isRequestCommand === true &&
+      !chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+    ) {
       return true;
-    } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
+    } else if (
+      isRequestCommand === true &&
+      chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+    ) {
       return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
     }
     logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
@@ -522,12 +525,12 @@ export class ChargingStationUtils {
   ): boolean {
     const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
     if (
-      isIncomingRequestCommand &&
+      isIncomingRequestCommand === true &&
       !chargingStation.stationInfo?.commandsSupport?.incomingCommands
     ) {
       return true;
     } else if (
-      isIncomingRequestCommand &&
+      isIncomingRequestCommand === true &&
       chargingStation.stationInfo?.commandsSupport?.incomingCommands
     ) {
       return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;