From d2ee9aa01c0eba5d06c4934b7d432da26d68f5bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 Mar 2026 00:09:30 +0100 Subject: [PATCH] feat: log once per key when OCPP 1.6 configuration key is remapped to OCPP 2.0 variable --- src/charging-station/ConfigurationKeyUtils.ts | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/charging-station/ConfigurationKeyUtils.ts b/src/charging-station/ConfigurationKeyUtils.ts index 90cb3cc8..8b08d03d 100644 --- a/src/charging-station/ConfigurationKeyUtils.ts +++ b/src/charging-station/ConfigurationKeyUtils.ts @@ -6,16 +6,39 @@ import { OCPPVersion, StandardParametersKey, } from '../types/index.js' -import { logger } from '../utils/index.js' +import { logger, once } 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, -} +const OCPP2_PARAMETER_KEY_MAP = new Map< + ConfigurationKeyType, + { + resolved: ConfigurationKeyType + warnOnce: (chargingStation: ChargingStation) => void + } + >( + ( + [ + [StandardParametersKey.AuthorizeRemoteTxRequests, StandardParametersKey.AuthorizeRemoteStart], + [StandardParametersKey.ConnectionTimeOut, StandardParametersKey.EVConnectionTimeOut], + [ + StandardParametersKey.LocalAuthorizeOffline, + StandardParametersKey.LocalAuthorizationOffline, + ], + [StandardParametersKey.LocalPreAuthorize, StandardParametersKey.LocalPreAuthorization], + [StandardParametersKey.MeterValueSampleInterval, StandardParametersKey.TxUpdatedInterval], + [StandardParametersKey.MeterValuesSampledData, StandardParametersKey.TxUpdatedMeasurands], + ] as [ConfigurationKeyType, ConfigurationKeyType][] + ).map(([from, to]) => [ + from, + { + resolved: to, + warnOnce: once((cs: ChargingStation) => { + logger.warn( + `${cs.logPrefix()} OCPP 1.6 configuration key '${from}' remapped to OCPP 2.0 variable '${to}'` + ) + }), + }, + ]) + ) const resolveKey = ( chargingStation: ChargingStation, @@ -23,7 +46,11 @@ const resolveKey = ( ): ConfigurationKeyType => { const version = chargingStation.stationInfo?.ocppVersion if (version === OCPPVersion.VERSION_20 || version === OCPPVersion.VERSION_201) { - return OCPP2_PARAMETER_KEY_MAP[key] ?? key + const mapping = OCPP2_PARAMETER_KEY_MAP.get(key) + if (mapping != null) { + mapping.warnOnce(chargingStation) + return mapping.resolved + } } return key } -- 2.43.0