Convert sendAuthorize to OCPP message sending handler
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 22:26:23 +0000 (23:26 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 22:26:23 +0000 (23:26 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index cf2f4277b862752becde11a3ab7ac283f142e9b7..eb45b056b80d6625e18be881b0d515789b95048c 100644 (file)
@@ -11,6 +11,7 @@ import {
 import type ChargingStation from './ChargingStation';
 import Constants from '../utils/Constants';
 import PerformanceStatistics from '../performance/PerformanceStatistics';
+import { RequestCommand } from '../types/ocpp/Requests';
 import { Status } from '../types/AutomaticTransactionGenerator';
 import Utils from '../utils/Utils';
 import logger from '../utils/Logger';
@@ -269,11 +270,15 @@ export default class AutomaticTransactionGenerator {
     if (this.chargingStation.hasAuthorizedTags()) {
       const idTag = this.chargingStation.getRandomIdTag();
       if (this.chargingStation.getAutomaticTransactionGeneratorRequireAuthorize()) {
+        this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
         // Authorize idTag
-        const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize(
-          connectorId,
-          idTag
-        );
+        const authorizeResponse: AuthorizeResponse =
+          (await this.chargingStation.ocppRequestService.sendMessageHandler(
+            RequestCommand.AUTHORIZE,
+            {
+              idTag,
+            }
+          )) as AuthorizeResponse;
         this.connectorsStatus.get(connectorId).authorizeRequests++;
         if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
           this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
index ed91c87ad9eab6f6db14baf135b13f75fcc13b85..13dac32d883e0b61a2a03152cf04828f7a8ee499 100644 (file)
@@ -34,6 +34,7 @@ import {
 import { Client, FTPResponse } from 'basic-ftp';
 import {
   OCPP16AuthorizationStatus,
+  OCPP16AuthorizeResponse,
   OCPP16StopTransactionReason,
 } from '../../../types/ocpp/1.6/Transaction';
 
@@ -535,10 +536,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               true;
             authorized = true;
           } else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
-            const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize(
-              transactionConnectorId,
-              commandPayload.idTag
-            );
+            this.chargingStation.getConnectorStatus(transactionConnectorId).authorizeIdTag =
+              commandPayload.idTag;
+            const authorizeResponse: OCPP16AuthorizeResponse =
+              (await this.chargingStation.ocppRequestService.sendMessageHandler(
+                OCPP16RequestCommand.AUTHORIZE,
+                {
+                  idTag: commandPayload.idTag,
+                }
+              )) as OCPP16AuthorizeResponse;
             if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
               authorized = true;
             }
index 295447b03fbb68039e8a1ba2399aa22ac1ccb81e..241e42f5d4e62533dcb512936fe3d7f4345d60a3 100644 (file)
@@ -2,7 +2,6 @@
 
 import {
   AuthorizeRequest,
-  OCPP16AuthorizeResponse,
   OCPP16StartTransactionResponse,
   OCPP16StopTransactionReason,
   OCPP16StopTransactionResponse,
@@ -23,8 +22,6 @@ import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
 import { JsonType } from '../../../types/JsonType';
-import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
-import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import OCPPError from '../../../exception/OCPPError';
@@ -63,21 +60,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
     );
   }
 
-  public async sendAuthorize(
-    connectorId: number,
-    idTag?: string
-  ): Promise<OCPP16AuthorizeResponse> {
-    const payload: AuthorizeRequest = {
-      ...(!Utils.isUndefined(idTag) ? { idTag } : { idTag: Constants.DEFAULT_IDTAG }),
-    };
-    this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
-    return (await this.sendMessage(
-      Utils.generateUUID(),
-      payload,
-      OCPP16RequestCommand.AUTHORIZE
-    )) as OCPP16AuthorizeResponse;
-  }
-
   public async sendStartTransaction(
     connectorId: number,
     idTag?: string
index 41e7a6eaa5c6f9d4581c6b2f915ab207ccb86570..4abf7ad31a2dbc5c3ad5f17debc84d8cd6b0b6e2 100644 (file)
@@ -1,9 +1,3 @@
-import {
-  AuthorizeResponse,
-  StartTransactionResponse,
-  StopTransactionReason,
-  StopTransactionResponse,
-} from '../../types/ocpp/Transaction';
 import {
   DiagnosticsStatus,
   IncomingRequestCommand,
@@ -11,10 +5,12 @@ import {
   ResponseType,
   SendParams,
 } from '../../types/ocpp/Requests';
+import {
+  StartTransactionResponse,
+  StopTransactionReason,
+  StopTransactionResponse,
+} from '../../types/ocpp/Transaction';
 
-import { BootNotificationResponse } from '../../types/ocpp/Responses';
-import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
-import { ChargePointStatus } from '../../types/ocpp/ChargePointStatus';
 import type ChargingStation from '../ChargingStation';
 import Constants from '../../utils/Constants';
 import { EmptyObject } from '../../types/EmptyObject';
@@ -333,7 +329,6 @@ export default abstract class OCPPRequestService {
     params?: SendParams
   ): Promise<ResponseType>;
 
-  public abstract sendAuthorize(connectorId: number, idTag?: string): Promise<AuthorizeResponse>;
   public abstract sendStartTransaction(
     connectorId: number,
     idTag?: string