Add BootNotification and ClearCache OCPP 2.0.1 commands support
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index 754d0fbfc5cbd0d22beb95ef126a2106a58c68db..7b6fe220b7a00aaa21a3c612e02fc493dfef3cc6 100644 (file)
@@ -1,11 +1,11 @@
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
 import fs from 'fs';
 import path from 'path';
 import { URL, fileURLToPath } from 'url';
 
 import type { JSONSchemaType } from 'ajv';
-import { Client, FTPResponse } from 'basic-ftp';
+import { Client, type FTPResponse } from 'basic-ftp';
 import tar from 'tar';
 
 import OCPPError from '../../../exception/OCPPError';
@@ -14,7 +14,7 @@ import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointE
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import {
   ChargingProfilePurposeType,
-  OCPP16ChargingProfile,
+  type OCPP16ChargingProfile,
 } from '../../../types/ocpp/1.6/ChargingProfile';
 import {
   OCPP16StandardParametersKey,
@@ -22,57 +22,58 @@ import {
 } from '../../../types/ocpp/1.6/Configuration';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import {
-  ChangeAvailabilityRequest,
-  ChangeConfigurationRequest,
-  ClearChargingProfileRequest,
-  DiagnosticsStatusNotificationRequest,
-  GetConfigurationRequest,
-  GetDiagnosticsRequest,
+  type ChangeAvailabilityRequest,
+  type ChangeConfigurationRequest,
+  type ClearChargingProfileRequest,
+  type DiagnosticsStatusNotificationRequest,
+  type GetConfigurationRequest,
+  type GetDiagnosticsRequest,
   OCPP16AvailabilityType,
-  OCPP16BootNotificationRequest,
-  OCPP16ClearCacheRequest,
-  OCPP16DataTransferRequest,
+  type OCPP16BootNotificationRequest,
+  type OCPP16ClearCacheRequest,
+  type OCPP16DataTransferRequest,
   OCPP16DataTransferVendorId,
-  OCPP16HeartbeatRequest,
+  type OCPP16HeartbeatRequest,
   OCPP16IncomingRequestCommand,
   OCPP16MessageTrigger,
   OCPP16RequestCommand,
-  OCPP16StatusNotificationRequest,
-  OCPP16TriggerMessageRequest,
-  OCPP16UpdateFirmwareRequest,
-  RemoteStartTransactionRequest,
-  RemoteStopTransactionRequest,
-  ResetRequest,
-  SetChargingProfileRequest,
-  UnlockConnectorRequest,
+  type OCPP16StatusNotificationRequest,
+  type OCPP16TriggerMessageRequest,
+  type OCPP16UpdateFirmwareRequest,
+  type RemoteStartTransactionRequest,
+  type RemoteStopTransactionRequest,
+  type ResetRequest,
+  type SetChargingProfileRequest,
+  type UnlockConnectorRequest,
 } from '../../../types/ocpp/1.6/Requests';
 import {
-  ChangeAvailabilityResponse,
-  ChangeConfigurationResponse,
-  ClearChargingProfileResponse,
-  DiagnosticsStatusNotificationResponse,
-  GetConfigurationResponse,
-  GetDiagnosticsResponse,
-  OCPP16BootNotificationResponse,
-  OCPP16DataTransferResponse,
+  type ChangeAvailabilityResponse,
+  type ChangeConfigurationResponse,
+  type ClearChargingProfileResponse,
+  type DiagnosticsStatusNotificationResponse,
+  type GetConfigurationResponse,
+  type GetDiagnosticsResponse,
+  type OCPP16BootNotificationResponse,
+  type OCPP16DataTransferResponse,
   OCPP16DataTransferStatus,
-  OCPP16HeartbeatResponse,
-  OCPP16StatusNotificationResponse,
-  OCPP16TriggerMessageResponse,
-  OCPP16UpdateFirmwareResponse,
-  SetChargingProfileResponse,
-  UnlockConnectorResponse,
+  type OCPP16HeartbeatResponse,
+  type OCPP16StatusNotificationResponse,
+  type OCPP16TriggerMessageResponse,
+  type OCPP16UpdateFirmwareResponse,
+  type SetChargingProfileResponse,
+  type UnlockConnectorResponse,
 } from '../../../types/ocpp/1.6/Responses';
 import {
   OCPP16AuthorizationStatus,
-  OCPP16AuthorizeRequest,
-  OCPP16AuthorizeResponse,
-  OCPP16StartTransactionRequest,
-  OCPP16StartTransactionResponse,
+  type OCPP16AuthorizeRequest,
+  type OCPP16AuthorizeResponse,
+  type OCPP16StartTransactionRequest,
+  type OCPP16StartTransactionResponse,
   OCPP16StopTransactionReason,
 } from '../../../types/ocpp/1.6/Transaction';
 import type { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
+import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
 import type { IncomingRequestHandler } from '../../../types/ocpp/Requests';
 import type { DefaultResponse } from '../../../types/ocpp/Responses';
 import Constants from '../../../utils/Constants';
@@ -94,7 +95,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     if (new.target?.name === moduleName) {
       throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
     }
-    super();
+    super(OCPPVersion.VERSION_16);
     this.incomingRequestHandlers = new Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>([
       [OCPP16IncomingRequestCommand.RESET, this.handleRequestReset.bind(this)],
       [OCPP16IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],