]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
feat: log once per key when OCPP 1.6 configuration key is remapped to OCPP 2.0 variable
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Mar 2026 23:09:30 +0000 (00:09 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Mar 2026 23:09:30 +0000 (00:09 +0100)
src/charging-station/ConfigurationKeyUtils.ts

index 90cb3cc8b5f30f9fe01e1547a459cffb401a3eeb..8b08d03d66170a4025f46e07a852f1a872aa3006 100644 (file)
@@ -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<Record<ConfigurationKeyType, ConfigurationKeyType>> = {
-  [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
 }