From: Jérôme Benoit Date: Sat, 30 Dec 2023 14:31:06 +0000 (+0100) Subject: fix: ensure configuration key visibility test does not alter configuration X-Git-Tag: v1.2.31~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=563e40cecd34ed272e3c2610c11dc42d09384bf9;p=e-mobility-charging-stations-simulator.git fix: ensure configuration key visibility test does not alter configuration Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 54741e67..e2e8dcba 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -502,27 +502,21 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { const unknownKey: string[] = [] if (key == null) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - for (const configuration of chargingStation.ocppConfiguration!.configurationKey!) { - if (configuration.visible == null) { - configuration.visible = true - } - if (!configuration.visible) { + for (const configKey of chargingStation.ocppConfiguration!.configurationKey!) { + if (!OCPP16ServiceUtils.isConfigurationKeyVisible(configKey)) { continue } configurationKey.push({ - key: configuration.key, - readonly: configuration.readonly, - value: configuration.value + key: configKey.key, + readonly: configKey.readonly, + value: configKey.value }) } } else if (isNotEmptyArray(key)) { for (const k of key) { const keyFound = getConfigurationKey(chargingStation, k, true) if (keyFound != null) { - if (keyFound.visible == null) { - keyFound.visible = true - } - if (!keyFound.visible) { + if (!OCPP16ServiceUtils.isConfigurationKeyVisible(keyFound)) { continue } configurationKey.push({ diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 2d31c051..d99e721e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -18,6 +18,7 @@ import { hasReservationExpired } from '../../../charging-station/index.js' import { + type ConfigurationKey, type GenericResponse, type JsonType, OCPP16AuthorizationStatus, @@ -37,7 +38,7 @@ import { type OCPP16SupportedFeatureProfiles, OCPPVersion } from '../../../types/index.js' -import { isNotEmptyArray, logger, roundTo } from '../../../utils/index.js' +import { cloneObject, isNotEmptyArray, logger, roundTo } from '../../../utils/index.js' import { OCPPServiceUtils } from '../OCPPServiceUtils.js' export class OCPP16ServiceUtils extends OCPPServiceUtils { @@ -431,6 +432,14 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { } } + public static isConfigurationKeyVisible (key: ConfigurationKey): boolean { + if (key.visible == null) { + key = cloneObject(key) + key.visible = true + } + return key.visible + } + public static hasReservation = ( chargingStation: ChargingStation, connectorId: number,