From 4c14964327482ed9c9282177d6110b9ef033de1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 13 Nov 2023 11:15:21 +0100 Subject: [PATCH] refactor: factor out voltage phase line to line computation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16ServiceUtils.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index a752ac99..502fd6a5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -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( -- 2.34.1