From 563e40cecd34ed272e3c2610c11dc42d09384bf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 30 Dec 2023 15:31:06 +0100 Subject: [PATCH] fix: ensure configuration key visibility test does not alter configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 18 ++++++------------ .../ocpp/1.6/OCPP16ServiceUtils.ts | 11 ++++++++++- 2 files changed, 16 insertions(+), 13 deletions(-) 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, -- 2.34.1