Handle null or undefined meterStart and meterStop properly
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 31 Dec 2022 21:34:23 +0000 (22:34 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 31 Dec 2022 21:34:23 +0000 (22:34 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts

index 25d8dcdf4a8fb33f9e2a5e43ec486f757d534878..040850a333f74e2bdcde662db8197081cda63b75 100644 (file)
@@ -698,7 +698,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     meterValue.sampledValue.push(
       OCPP16ServiceUtils.buildSampledValue(
         sampledValueTemplate,
-        Utils.roundTo(meterStart / unitDivider, 4),
+        Utils.roundTo((meterStart ?? 0) / unitDivider, 4),
         MeterValueContext.TRANSACTION_BEGIN
       )
     );
@@ -723,7 +723,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     meterValue.sampledValue.push(
       OCPP16ServiceUtils.buildSampledValue(
         sampledValueTemplate,
-        Utils.roundTo(meterStop / unitDivider, 4),
+        Utils.roundTo((meterStop ?? 0) / unitDivider, 4),
         MeterValueContext.TRANSACTION_END
       )
     );