refactor: factor out feature profile test
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16RequestService.ts
index fb5007247d51f464d6cdbbacc99a322a685ae0cc..ac1c1ac30d8810ac85e00de9b94b438e4e9876a0 100644 (file)
@@ -44,7 +44,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
           'assets/json-schemas/ocpp/1.6/Authorize.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -52,7 +52,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationRequest>(
           'assets/json-schemas/ocpp/1.6/BootNotification.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -60,7 +60,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationRequest>(
           'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -68,7 +68,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatRequest>(
           'assets/json-schemas/ocpp/1.6/Heartbeat.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -76,7 +76,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesRequest>(
           'assets/json-schemas/ocpp/1.6/MeterValues.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -84,7 +84,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationRequest>(
           'assets/json-schemas/ocpp/1.6/StatusNotification.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -92,7 +92,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionRequest>(
           'assets/json-schemas/ocpp/1.6/StartTransaction.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -100,7 +100,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionRequest>(
           'assets/json-schemas/ocpp/1.6/StopTransaction.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -108,7 +108,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
           'assets/json-schemas/ocpp/1.6/DataTransfer.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
       [
@@ -116,14 +116,14 @@ export class OCPP16RequestService extends OCPPRequestService {
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationRequest>(
           'assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json',
           moduleName,
-          'constructor'
+          'constructor',
         ),
       ],
     ]);
     this.buildRequestPayload = this.buildRequestPayload.bind(this) as <Request extends JsonType>(
       chargingStation: ChargingStation,
       commandName: OCPP16RequestCommand,
-      commandParams?: JsonType
+      commandParams?: JsonType,
     ) => Request;
   }
 
@@ -131,7 +131,7 @@ export class OCPP16RequestService extends OCPPRequestService {
     chargingStation: ChargingStation,
     commandName: OCPP16RequestCommand,
     commandParams?: JsonType,
-    params?: RequestParams
+    params?: RequestParams,
   ): Promise<ResponseType> {
     // FIXME?: add sanity checks on charging station availability, connector availability, connector status, etc.
     if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) {
@@ -140,7 +140,7 @@ export class OCPP16RequestService extends OCPPRequestService {
         generateUUID(),
         this.buildRequestPayload<RequestType>(chargingStation, commandName, commandParams),
         commandName,
-        params
+        params,
       )) as ResponseType;
     }
     // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
@@ -148,16 +148,16 @@ export class OCPP16RequestService extends OCPPRequestService {
       ErrorType.NOT_SUPPORTED,
       `Unsupported OCPP command '${commandName}'`,
       commandName,
-      commandParams
+      commandParams,
     );
   }
 
   private buildRequestPayload<Request extends JsonType>(
     chargingStation: ChargingStation,
     commandName: OCPP16RequestCommand,
-    commandParams?: JsonType
+    commandParams?: JsonType,
   ): Request {
-    let connectorId: number;
+    let connectorId: number | undefined;
     let energyActiveImportRegister: number;
     commandParams = commandParams as JsonObject;
     switch (commandName) {
@@ -180,7 +180,7 @@ export class OCPP16RequestService extends OCPPRequestService {
           idTag: Constants.DEFAULT_IDTAG,
           meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId(
             commandParams?.connectorId as number,
-            true
+            true,
           ),
           timestamp: new Date(),
           ...commandParams,
@@ -188,11 +188,11 @@ export class OCPP16RequestService extends OCPPRequestService {
       case OCPP16RequestCommand.STOP_TRANSACTION:
         chargingStation.getTransactionDataMeterValues() &&
           (connectorId = chargingStation.getConnectorIdByTransactionId(
-            commandParams?.transactionId as number
-          ));
+            commandParams?.transactionId as number,
+          )!);
         energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
           commandParams?.transactionId as number,
-          true
+          true,
         );
         return {
           idTag: chargingStation.getTransactionIdTag(commandParams?.transactionId as number),
@@ -200,12 +200,12 @@ export class OCPP16RequestService extends OCPPRequestService {
           timestamp: new Date(),
           ...(chargingStation.getTransactionDataMeterValues() && {
             transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
-              chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
+              chargingStation.getConnectorStatus(connectorId!)!.transactionBeginMeterValue!,
               OCPP16ServiceUtils.buildTransactionEndMeterValue(
                 chargingStation,
-                connectorId,
-                energyActiveImportRegister
-              )
+                connectorId!,
+                energyActiveImportRegister,
+              ),
             ),
           }),
           ...commandParams,
@@ -217,7 +217,7 @@ export class OCPP16RequestService extends OCPPRequestService {
           // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
           `Unsupported OCPP command '${commandName}'`,
           commandName,
-          commandParams
+          commandParams,
         );
     }
   }