From cfdf901dfbdf4cf745a1ced9b7870251cb9c6f10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 31 Jul 2023 11:35:31 +0200 Subject: [PATCH] refactor: cleanup RFID tags authorization code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 2 +- src/charging-station/ChargingStation.ts | 4 ++-- src/charging-station/Helpers.ts | 1 + .../ocpp/1.6/OCPP16IncomingRequestService.ts | 10 ---------- .../ocpp/1.6/OCPP16ResponseService.ts | 2 +- src/charging-station/ocpp/OCPPServiceUtils.ts | 13 ++++++++++--- src/types/ChargingStationTemplate.ts | 2 ++ ui/web/src/types/ChargingStationType.ts | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0fccb03f..161d5712 100644 --- 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 | diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 1636f547..eb73f002 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 { diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 7f32b487..6cd270ff 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -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( diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7599e39b..356e453b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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 && diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 12b10087..0f697f63 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -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 ) { diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index a9c5c562..b7474087 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -227,13 +227,21 @@ export class OCPPServiceUtils { connectorId: number, idTag: string, ): Promise { + 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 diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 78078375..68c20597 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -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; diff --git a/ui/web/src/types/ChargingStationType.ts b/ui/web/src/types/ChargingStationType.ts index b391bef5..45418353 100644 --- a/ui/web/src/types/ChargingStationType.ts +++ b/ui/web/src/types/ChargingStationType.ts @@ -57,7 +57,7 @@ export type ChargingStationInfo = { reconnectExponentialDelay?: boolean; registrationMaxRetries?: number; enableStatistics?: boolean; - mustAuthorizeAtRemoteStart?: boolean; + remoteAuthorization?: boolean; amperageLimitationOcppKey?: string; amperageLimitationUnit?: AmpereUnits; beginEndMeterValues?: boolean; -- 2.34.1