Silence sonar cleanups
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16RequestService.ts
index fef9d86daa6cbe3a855b8e9c3d09b27584ae9eee..afc4773d3cbc34914991faad8df89f6cdffbd4a9 100644 (file)
@@ -27,7 +27,6 @@ import Constants from '../../../utils/Constants';
 import logger from '../../../utils/Logger';
 import Utils from '../../../utils/Utils';
 import type ChargingStation from '../../ChargingStation';
-import { ChargingStationUtils } from '../../ChargingStationUtils';
 import OCPPRequestService from '../OCPPRequestService';
 import type OCPPResponseService from '../OCPPResponseService';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
@@ -150,7 +149,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
     commandParams?: JsonType,
     params?: RequestParams
   ): Promise<ResponseType> {
-    if (ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)) {
+    if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) {
       const requestPayload = this.buildRequestPayload<RequestType>(
         chargingStation,
         commandName,
@@ -165,6 +164,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
         params
       )) as unknown as ResponseType;
     }
+    // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
     throw new OCPPError(
       ErrorType.NOT_SUPPORTED,
       `Unsupported OCPP command '${commandName}'`,
@@ -243,10 +243,12 @@ export default class OCPP16RequestService extends OCPPRequestService {
         connectorId = chargingStation.getConnectorIdByTransactionId(
           commandParams?.transactionId as number
         );
-        energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
-          commandParams?.transactionId as number,
-          true
-        );
+        commandParams?.meterStop &&
+          (energyActiveImportRegister =
+            chargingStation.getEnergyActiveImportRegisterByTransactionId(
+              commandParams?.transactionId as number,
+              true
+            ));
         return {
           transactionId: commandParams?.transactionId,
           idTag:
@@ -267,6 +269,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
           }),
         } as unknown as Request;
       default:
+        // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
         throw new OCPPError(
           ErrorType.NOT_SUPPORTED,
           // eslint-disable-next-line @typescript-eslint/restrict-template-expressions