Fix undefined meterStop at sending stopTransaction
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ServiceUtils.ts
index 1c8e1369b25fe997e9aac7ac509b3a91eb9c4920..2a154e7b78e9dd26a6ebb2b300f968c7dba3f712 100644 (file)
@@ -1,10 +1,15 @@
 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
 
-import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
+import OCPPError from '../../../exception/OCPPError';
 import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
 import MeasurandPerPhaseSampledValueTemplates, {
   SampledValueTemplate,
 } from '../../../types/MeasurandPerPhaseSampledValueTemplates';
+import MeasurandValues from '../../../types/MeasurandValues';
+import {
+  OCPP16StandardParametersKey,
+  OCPP16SupportedFeatureProfiles,
+} from '../../../types/ocpp/1.6/Configuration';
 import {
   MeterValueContext,
   MeterValueLocation,
@@ -18,20 +23,14 @@ import {
   OCPP16IncomingRequestCommand,
   OCPP16RequestCommand,
 } from '../../../types/ocpp/1.6/Requests';
-import {
-  OCPP16StandardParametersKey,
-  OCPP16SupportedFeatureProfiles,
-} from '../../../types/ocpp/1.6/Configuration';
-
+import { ErrorType } from '../../../types/ocpp/ErrorType';
+import Constants from '../../../utils/Constants';
+import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
+import logger from '../../../utils/Logger';
+import Utils from '../../../utils/Utils';
 import type ChargingStation from '../../ChargingStation';
 import { ChargingStationUtils } from '../../ChargingStationUtils';
-import Constants from '../../../utils/Constants';
-import { ErrorType } from '../../../types/ocpp/ErrorType';
-import MeasurandValues from '../../../types/MeasurandValues';
-import OCPPError from '../../../exception/OCPPError';
 import { OCPPServiceUtils } from '../OCPPServiceUtils';
-import Utils from '../../../utils/Utils';
-import logger from '../../../utils/Logger';
 
 export class OCPP16ServiceUtils extends OCPPServiceUtils {
   public static checkFeatureProfile(
@@ -770,16 +769,16 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     chargingStation: ChargingStation,
     measurandType: OCPP16MeterValueMeasurand
   ): void {
-    if (Utils.isUndefined(chargingStation.stationInfo.powerDivider)) {
+    if (Utils.isUndefined(chargingStation.powerDivider)) {
       const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${
         measurandType ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
       }: powerDivider is undefined`;
       logger.error(errMsg);
       throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES);
-    } else if (chargingStation.stationInfo?.powerDivider <= 0) {
+    } else if (chargingStation?.powerDivider <= 0) {
       const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${
         measurandType ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-      }: powerDivider have zero or below value ${chargingStation.stationInfo.powerDivider}`;
+      }: powerDivider have zero or below value ${chargingStation.powerDivider}`;
       logger.error(errMsg);
       throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES);
     }