refactor: trivial cleanups
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 2.0 / OCPP20IncomingRequestService.ts
index 95169e2b0d88f548a6829bde7cbeed6a314f3991..3fdb5cedf1b784c5b90c93706e05596557f0afe5 100644 (file)
@@ -3,6 +3,7 @@
 import type { JSONSchemaType } from 'ajv';
 
 import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
+import type { ChargingStation } from '../../../charging-station';
 import { OCPPError } from '../../../exception';
 import {
   ErrorType,
@@ -13,8 +14,7 @@ import {
   OCPP20IncomingRequestCommand,
   OCPPVersion,
 } from '../../../types';
-import { logger } from '../../../utils/Logger';
-import type { ChargingStation } from '../../ChargingStation';
+import { logger } from '../../../utils';
 import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService';
 
 const moduleName = 'OCPP20IncomingRequestService';
@@ -24,9 +24,9 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
   private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
 
   public constructor() {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_20);
     this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
       [OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
@@ -35,13 +35,17 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
       [
         OCPP20IncomingRequestCommand.CLEAR_CACHE,
         OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
-          '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
+          'assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
           moduleName,
           'constructor'
         ),
       ],
     ]);
-    this.validatePayload.bind(this);
+    this.validatePayload = this.validatePayload.bind(this) as (
+      chargingStation: ChargingStation,
+      commandName: OCPP20IncomingRequestCommand,
+      commandPayload: JsonType
+    ) => boolean;
   }
 
   public async incomingRequestHandler(
@@ -53,7 +57,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     let response: JsonType;
     if (
       chargingStation.getOcppStrictCompliance() === true &&
-      chargingStation.isInPendingState() === true &&
+      chargingStation.inPendingState() === true &&
       (commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
         commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
     ) {
@@ -71,7 +75,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     if (
       chargingStation.isRegistered() === true ||
       (chargingStation.getOcppStrictCompliance() === false &&
-        chargingStation.isInUnknownState() === true)
+        chargingStation.inUnknownState() === true)
     ) {
       if (
         this.incomingRequestHandlers.has(commandName) === true &&