refactor: factor out voltage phase line to line computation
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 13 Nov 2023 10:15:21 +0000 (11:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 13 Nov 2023 10:15:21 +0000 (11:15 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts

index a752ac9927e2932d4eac5700acb7505db20c9903..502fd6a57c2fde8d27eca15f4b78ab62aba66f72 100644 (file)
@@ -194,6 +194,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
               ? (phase + 1) % chargingStation.getNumberOfPhases()
               : chargingStation.getNumberOfPhases()
           }`;
+          const voltagePhaseLineToLineValueRounded = roundTo(
+            Math.sqrt(chargingStation.getNumberOfPhases()) *
+              chargingStation.stationInfo.voltageOut!,
+            2,
+          );
           const voltagePhaseLineToLineSampledValueTemplate =
             OCPP16ServiceUtils.getSampledValueTemplate(
               chargingStation,
@@ -207,11 +212,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
               voltagePhaseLineToLineSampledValueTemplate.value,
             )
               ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value)
-              : roundTo(
-                  Math.sqrt(chargingStation.getNumberOfPhases()) *
-                    chargingStation.stationInfo.voltageOut!,
-                  2,
-                );
+              : voltagePhaseLineToLineValueRounded;
             const fluctuationPhaseLineToLinePercent =
               voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ??
               Constants.DEFAULT_FLUCTUATION_PERCENT;
@@ -221,8 +222,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
             );
           }
           const defaultVoltagePhaseLineToLineMeasurandValue = getRandomFloatFluctuatedRounded(
-            Math.sqrt(chargingStation.getNumberOfPhases()) *
-              chargingStation.stationInfo.voltageOut!,
+            voltagePhaseLineToLineValueRounded,
             fluctuationPercent,
           );
           meterValue.sampledValue.push(