From 405ad5f556cf9873ecc457df7217cfaf20f470ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 26 Mar 2026 23:09:05 +0100 Subject: [PATCH] fix: align OCPP 2.0 variable names to spec (LocalPreAuthorization, LocalAuthorizationOffline) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Rename LocalPreAuthorize → LocalPreAuthorization and LocalAuthorizeOffline → LocalAuthorizationOffline to match the OCPP 2.0.1 appendix. Add key resolution mapping for both. Replace string literals with enum references in OCPP20AuthAdapter. --- .../keba-ocpp2.station-template.json | 2 +- src/charging-station/ConfigurationKeyUtils.ts | 2 ++ .../ocpp/2.0/OCPP20IncomingRequestService.ts | 2 +- .../ocpp/2.0/OCPP20VariableRegistry.ts | 8 ++--- .../ocpp/auth/adapters/OCPP20AuthAdapter.ts | 30 ++++++++++++------- src/types/ocpp/2.0/Variables.ts | 4 +-- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/assets/station-templates/keba-ocpp2.station-template.json b/src/assets/station-templates/keba-ocpp2.station-template.json index ecdbb1d7..dabea003 100644 --- a/src/assets/station-templates/keba-ocpp2.station-template.json +++ b/src/assets/station-templates/keba-ocpp2.station-template.json @@ -32,7 +32,7 @@ "value": "false" }, { - "key": "LocalPreAuthorize", + "key": "LocalPreAuthorization", "readonly": false, "value": "false" }, diff --git a/src/charging-station/ConfigurationKeyUtils.ts b/src/charging-station/ConfigurationKeyUtils.ts index 2c97bbaa..90cb3cc8 100644 --- a/src/charging-station/ConfigurationKeyUtils.ts +++ b/src/charging-station/ConfigurationKeyUtils.ts @@ -11,6 +11,8 @@ import { logger } from '../utils/index.js' const OCPP2_PARAMETER_KEY_MAP: Partial> = { [StandardParametersKey.AuthorizeRemoteTxRequests]: StandardParametersKey.AuthorizeRemoteStart, [StandardParametersKey.ConnectionTimeOut]: StandardParametersKey.EVConnectionTimeOut, + [StandardParametersKey.LocalAuthorizeOffline]: StandardParametersKey.LocalAuthorizationOffline, + [StandardParametersKey.LocalPreAuthorize]: StandardParametersKey.LocalPreAuthorization, [StandardParametersKey.MeterValueSampleInterval]: StandardParametersKey.TxUpdatedInterval, [StandardParametersKey.MeterValuesSampledData]: StandardParametersKey.TxUpdatedMeasurands, } diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 417f6aa8..bc7e9328 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -2930,7 +2930,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { * OCPP 2.0 Authorization Logic Implementation * * OCPP 2.0 handles authorization differently from 1.6: - * 1. Check if authorization is required (LocalAuthorizeOffline, AuthorizeRemoteStart variables) + * 1. Check if authorization is required (LocalAuthorizationOffline, AuthorizeRemoteStart variables) * 2. Local authorization list validation if enabled * 3. For OCPP 2.0, there's no explicit AuthorizeRequest - authorization is validated * through configuration variables and local auth lists diff --git a/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts b/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts index 469944c6..cc23745a 100644 --- a/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts +++ b/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts @@ -397,7 +397,7 @@ export const VARIABLE_REGISTRY: Record = { }, [buildRegistryKey( OCPP20ComponentName.AuthCtrlr as string, - OCPP20RequiredVariableName.LocalAuthorizeOffline + OCPP20RequiredVariableName.LocalAuthorizationOffline )]: { component: OCPP20ComponentName.AuthCtrlr as string, dataType: DataEnumType.boolean, @@ -407,11 +407,11 @@ export const VARIABLE_REGISTRY: Record = { persistence: PersistenceEnumType.Persistent, required: true, supportedAttributes: [AttributeEnumType.Actual], - variable: OCPP20RequiredVariableName.LocalAuthorizeOffline as string, + variable: OCPP20RequiredVariableName.LocalAuthorizationOffline as string, }, [buildRegistryKey( OCPP20ComponentName.AuthCtrlr as string, - OCPP20RequiredVariableName.LocalPreAuthorize + OCPP20RequiredVariableName.LocalPreAuthorization )]: { component: OCPP20ComponentName.AuthCtrlr as string, dataType: DataEnumType.boolean, @@ -421,7 +421,7 @@ export const VARIABLE_REGISTRY: Record = { persistence: PersistenceEnumType.Persistent, required: true, supportedAttributes: [AttributeEnumType.Actual], - variable: OCPP20RequiredVariableName.LocalPreAuthorize as string, + variable: OCPP20RequiredVariableName.LocalPreAuthorization as string, }, // CHAdeMOCtrlr Component diff --git a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts index 21ed9af8..98c0fd47 100644 --- a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts +++ b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts @@ -16,9 +16,11 @@ import type { import { OCPP20VariableManager } from '../../2.0/OCPP20VariableManager.js' import { GetVariableStatusEnumType, + OCPP20ComponentName, OCPP20IdTokenEnumType, type OCPP20IdTokenType, OCPP20RequestCommand, + OCPP20RequiredVariableName, OCPPVersion, } from '../../../../types/index.js' import { logger, truncateId } from '../../../../utils/index.js' @@ -394,7 +396,10 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { const isOnline = this.chargingStation.inAcceptedState() // Check AuthorizeRemoteStart variable (with type validation) - const remoteStartValue = this.getVariableValue('AuthCtrlr', 'AuthorizeRemoteStart') + const remoteStartValue = this.getVariableValue( + OCPP20ComponentName.AuthCtrlr, + OCPP20RequiredVariableName.AuthorizeRemoteStart + ) const remoteStartEnabled = this.parseBooleanVariable(remoteStartValue, true) return isOnline && remoteStartEnabled @@ -478,8 +483,8 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { /** * Get default variable value based on OCPP 2.0.1 specification - * @param component - OCPP component name (e.g., 'AuthCtrlr') - * @param variable - OCPP variable name (e.g., 'AuthorizeRemoteStart') + * @param component - OCPP component name (e.g., OCPP20ComponentName.AuthCtrlr) + * @param variable - OCPP variable name (e.g., OCPP20RequiredVariableName.AuthorizeRemoteStart) * @param useFallback - Whether to return fallback values when variable is not configured * @returns Default value according to OCPP 2.0.1 spec, or undefined if no default exists */ @@ -493,17 +498,17 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { } // Default values from OCPP 2.0.1 specification and variable registry - if (component === 'AuthCtrlr') { + if (component === (OCPP20ComponentName.AuthCtrlr as string)) { switch (variable) { - case 'AuthorizeRemoteStart': - return 'true' // OCPP 2.0.1 default: remote start requires authorization case 'Enabled': return 'true' // Default: authorization is enabled case 'LocalAuthListEnabled': return 'true' // Default: enable local auth list - case 'LocalAuthorizeOffline': + case OCPP20RequiredVariableName.AuthorizeRemoteStart as string: + return 'true' // OCPP 2.0.1 default: remote start requires authorization + case OCPP20RequiredVariableName.LocalAuthorizationOffline as string: return 'true' // OCPP 2.0.1 default: allow offline authorization - case 'LocalPreAuthorize': + case OCPP20RequiredVariableName.LocalPreAuthorization as string: return 'false' // OCPP 2.0.1 default: wait for CSMS authorization default: return undefined @@ -519,7 +524,10 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { */ private getOfflineAuthorizationConfig (): boolean { try { - const value = this.getVariableValue('AuthCtrlr', 'LocalAuthorizeOffline') + const value = this.getVariableValue( + OCPP20ComponentName.AuthCtrlr, + OCPP20RequiredVariableName.LocalAuthorizationOffline + ) return this.parseBooleanVariable(value, true) } catch (error) { logger.warn( @@ -532,8 +540,8 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { /** * Get variable value from OCPP 2.0 variable system - * @param component - OCPP component name (e.g., 'AuthCtrlr') - * @param variable - OCPP variable name (e.g., 'AuthorizeRemoteStart') + * @param component - OCPP component name (e.g., OCPP20ComponentName.AuthCtrlr) + * @param variable - OCPP variable name (e.g., OCPP20RequiredVariableName.AuthorizeRemoteStart) * @param useDefaultFallback - If true, use OCPP 2.0.1 spec default values when variable is not found * @returns Promise resolving to variable value as string, or undefined if not available */ diff --git a/src/types/ocpp/2.0/Variables.ts b/src/types/ocpp/2.0/Variables.ts index 619ea2da..b25f1b9d 100644 --- a/src/types/ocpp/2.0/Variables.ts +++ b/src/types/ocpp/2.0/Variables.ts @@ -47,8 +47,8 @@ export enum OCPP20RequiredVariableName { EVConnectionTimeOut = 'EVConnectionTimeOut', FileTransferProtocols = 'FileTransferProtocols', ItemsPerMessage = 'ItemsPerMessage', - LocalAuthorizeOffline = 'LocalAuthorizeOffline', - LocalPreAuthorize = 'LocalPreAuthorize', + LocalAuthorizationOffline = 'LocalAuthorizationOffline', + LocalPreAuthorization = 'LocalPreAuthorization', MessageAttemptInterval = 'MessageAttemptInterval', MessageAttempts = 'MessageAttempts', MessageTimeout = 'MessageTimeout', -- 2.43.0