fix: ensure built sample meterValues value can't be overriden
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Nov 2023 19:43:32 +0000 (20:43 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Nov 2023 19:43:32 +0000 (20:43 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts

index b28d682e9d654066143214f6ba834b017f1bcdaa..6628fb819a0a5d1dbe6951d625ecccf5198a47a3 100644 (file)
@@ -1335,7 +1335,6 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     context?: MeterValueContext,
     phase?: OCPP16MeterValuePhase,
   ): OCPP16SampledValue {
-    const sampledValueValue = value ?? sampledValueTemplate?.value;
     const sampledValueContext = context ?? sampledValueTemplate?.context;
     const sampledValueLocation =
       sampledValueTemplate?.location ??
@@ -1350,7 +1349,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         measurand: sampledValueTemplate.measurand,
       }),
       ...(!isNullOrUndefined(sampledValueLocation) && { location: sampledValueLocation }),
-      ...(!isNullOrUndefined(sampledValueValue) && { value: sampledValueValue.toString() }),
+      ...(!isNullOrUndefined(value) && { value: value.toString() }),
       ...(!isNullOrUndefined(sampledValuePhase) && { phase: sampledValuePhase }),
     } as OCPP16SampledValue;
   }