refactor: cleanup RFID tags authorization code
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 31 Jul 2023 09:35:31 +0000 (11:35 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 31 Jul 2023 09:35:31 +0000 (11:35 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts
src/types/ChargingStationTemplate.ts
ui/web/src/types/ChargingStationType.ts

index 0fccb03fa9355acd601bc2568cd484984df14e5a..161d571279e126ef587e5f4b4bdd55809ff0bde0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -166,7 +166,7 @@ But the modifications to test have to be done to the files in the build target d
 | amperageLimitationOcppKey                            |               | undefined                                                                                                                          | string                                                                                                                                                                   | charging stations OCPP parameter key used to set the amperage limit, per phase for each connector on AC and global for DC                                                                                                                  |
 | amperageLimitationUnit                               | A/cA/dA/mA    | A                                                                                                                                  | string                                                                                                                                                                   | charging stations amperage limit unit                                                                                                                                                                                                      |
 | enableStatistics                                     | true/false    | false                                                                                                                              | boolean                                                                                                                                                                  | enable charging stations statistics                                                                                                                                                                                                        |
-| mustAuthorizeAtRemoteStart                           | true/false    | true                                                                                                                               | boolean                                                                                                                                                                  | always send authorize at remote start transaction when AuthorizeRemoteTxRequests is enabled                                                                                                                                                |
+| remoteAuthorization                                  | true/false    | true                                                                                                                               | boolean                                                                                                                                                                  | enable RFID tags remote authorization                                                                                                                                                                                                      |
 | beginEndMeterValues                                  | true/false    | false                                                                                                                              | boolean                                                                                                                                                                  | enable Transaction.{Begin,End} MeterValues                                                                                                                                                                                                 |
 | outOfOrderEndMeterValues                             | true/false    | false                                                                                                                              | boolean                                                                                                                                                                  | send Transaction.End MeterValues out of order. Need to relax OCPP specifications strict compliance ('ocppStrictCompliance' parameter)                                                                                                      |
 | meteringPerTransaction                               | true/false    | true                                                                                                                               | boolean                                                                                                                                                                  | enable metering history on a per transaction basis                                                                                                                                                                                         |
index 1636f5470b42c58bf4c0d2e00476d19e1f489bc3..eb73f002c90f0cbc5289a59550dece1364ce6c7a 100644 (file)
@@ -246,8 +246,8 @@ export class ChargingStation {
     return this.stationInfo.enableStatistics ?? false;
   }
 
-  public getMustAuthorizeAtRemoteStart(): boolean {
-    return this.stationInfo.mustAuthorizeAtRemoteStart ?? true;
+  public getRemoteAuthorization(): boolean {
+    return this.stationInfo.remoteAuthorization ?? true;
   }
 
   public getNumberOfPhases(stationInfo?: ChargingStationInfo): number {
index 7f32b4871d3e0c717af79e46d093958419b32e92..6cd270ffee29855891f0d79a6565af6547283c85 100644 (file)
@@ -377,6 +377,7 @@ export const warnTemplateKeysDeprecation = (
     { deprecatedKey: 'supervisionUrl', key: 'supervisionUrls' },
     { deprecatedKey: 'authorizationFile', key: 'idTagsFile' },
     { deprecatedKey: 'payloadSchemaValidation', key: 'ocppStrictCompliance' },
+    { deprecatedKey: 'mustAuthorizeAtRemoteStart', key: 'remoteAuthorization' },
   ];
   for (const templateKey of templateKeys) {
     warnDeprecatedTemplateKey(
index 7599e39b0101f777ca8aaa26338d2a591a7accbf..356e453bde54863444e4fd4589c7432871a5f83a 100644 (file)
@@ -861,16 +861,6 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       OCPP16ChargePointStatus.Preparing,
     );
     const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId)!;
-    if (
-      chargingStation.getAuthorizeRemoteTxRequests() &&
-      !chargingStation.getLocalAuthListEnabled() &&
-      !chargingStation.getMustAuthorizeAtRemoteStart()
-    ) {
-      logger.warn(
-        `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction
-          but local authorization or must authorize at remote start isn't enabled`,
-      );
-    }
     // Authorization check required
     if (
       chargingStation.getAuthorizeRemoteTxRequests() === true &&
index 12b10087a5f4fecfbe322e8693bbd160f4efc95b..0f697f630fe079a0b0e9aa72c6c13ed2154e631c 100644 (file)
@@ -529,7 +529,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       chargingStation.getConnectorStatus(transactionConnectorId)?.transactionRemoteStarted ===
         true &&
       chargingStation.getAuthorizeRemoteTxRequests() === true &&
-      chargingStation.getMustAuthorizeAtRemoteStart() === true &&
+      chargingStation.getRemoteAuthorization() === true &&
       chargingStation.getConnectorStatus(transactionConnectorId)?.idTagLocalAuthorized === false &&
       chargingStation.getConnectorStatus(transactionConnectorId)?.idTagAuthorized === false
     ) {
index a9c5c562ea18c47e4d88470ca2a54831736af31a..b74740875b2753642eb673ae3dcd9a8cb5a3c89a 100644 (file)
@@ -227,13 +227,21 @@ export class OCPPServiceUtils {
     connectorId: number,
     idTag: string,
   ): Promise<boolean> {
+    if (!chargingStation.getLocalAuthListEnabled() && !chargingStation.getRemoteAuthorization()) {
+      logger.warn(
+        `${chargingStation.logPrefix()} The charging station expects to authorize RFID tags but nor local authorization nor remote authorization are enabled. Misbehavior may occur`,
+      );
+    }
     let authorized = false;
-    if (OCPPServiceUtils.isIdTagLocalAuthorized(chargingStation, idTag)) {
+    if (
+      chargingStation.getLocalAuthListEnabled() === true &&
+      OCPPServiceUtils.isIdTagLocalAuthorized(chargingStation, idTag)
+    ) {
       const connectorStatus: ConnectorStatus = chargingStation.getConnectorStatus(connectorId)!;
       connectorStatus.localAuthorizeIdTag = idTag;
       connectorStatus.idTagLocalAuthorized = true;
       authorized = true;
-    } else if (chargingStation.getMustAuthorizeAtRemoteStart()) {
+    } else if (chargingStation.getRemoteAuthorization()) {
       authorized = await OCPPServiceUtils.isIdTagRemoteAuthorized(
         chargingStation,
         connectorId,
@@ -424,7 +432,6 @@ export class OCPPServiceUtils {
 
   private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {
     return (
-      chargingStation.getLocalAuthListEnabled() === true &&
       chargingStation.hasIdTags() === true &&
       isNotEmptyString(
         chargingStation.idTagsCache
index 7807837573fac8aed4fcbef66dcd73a9023cb180..68c20597c4edf2cbf8f5db99fe61ab6e3d970ea2 100644 (file)
@@ -108,6 +108,8 @@ export interface ChargingStationTemplate {
   reconnectExponentialDelay?: boolean;
   registrationMaxRetries?: number;
   enableStatistics?: boolean;
+  remoteAuthorization?: boolean;
+  /** @deprecated Replaced by remoteAuthorization */
   mustAuthorizeAtRemoteStart?: boolean;
   /** @deprecated Replaced by ocppStrictCompliance */
   payloadSchemaValidation?: boolean;
index b391bef5188f2497b139e42105c85ec93f3268ce..45418353adca329d7836d37db01fd76aebbe24b2 100644 (file)
@@ -57,7 +57,7 @@ export type ChargingStationInfo = {
   reconnectExponentialDelay?: boolean;
   registrationMaxRetries?: number;
   enableStatistics?: boolean;
-  mustAuthorizeAtRemoteStart?: boolean;
+  remoteAuthorization?: boolean;
   amperageLimitationOcppKey?: string;
   amperageLimitationUnit?: AmpereUnits;
   beginEndMeterValues?: boolean;