From a723e7e9df355545fc6a41bdcbb9debfae22db5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 6 Sep 2022 01:48:33 +0200 Subject: [PATCH] Add types to OCPP configuration key handling code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ChargingStationConfigurationUtils.ts | 12 ++++++++---- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index 004b95fc..f79a7375 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -3,6 +3,10 @@ import type { StandardParametersKey } from '../types/ocpp/Configuration'; import logger from '../utils/Logger'; import type ChargingStation from './ChargingStation'; +type ConfigurationKeyOptions = { readonly?: boolean; visible?: boolean; reboot?: boolean }; +type DeleteConfigurationKeyParams = { save?: boolean; caseInsensitive?: boolean }; +type AddConfigurationKeyParams = { overwrite?: boolean; save?: boolean }; + export class ChargingStationConfigurationUtils { private constructor() { // This is intentional @@ -25,14 +29,14 @@ export class ChargingStationConfigurationUtils { chargingStation: ChargingStation, key: string | StandardParametersKey, value: string, - options: { readonly?: boolean; visible?: boolean; reboot?: boolean } = { + options: ConfigurationKeyOptions = { readonly: false, visible: true, reboot: false, }, - params: { overwrite?: boolean; save?: boolean } = { overwrite: false, save: false } + params: AddConfigurationKeyParams = { overwrite: false, save: false } ): void { - options = options ?? ({} as { readonly?: boolean; visible?: boolean; reboot?: boolean }); + options = options ?? ({} as ConfigurationKeyOptions); options.readonly = options?.readonly ?? false; options.visible = options?.visible ?? true; options.reboot = options?.reboot ?? false; @@ -87,7 +91,7 @@ export class ChargingStationConfigurationUtils { public static deleteConfigurationKey( chargingStation: ChargingStation, key: string | StandardParametersKey, - params: { save?: boolean; caseInsensitive?: boolean } = { save: true, caseInsensitive: false } + params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false } ): ConfigurationKey[] { const keyFound = ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 6c11ad57..d09e69a1 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -435,9 +435,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ): GetConfigurationResponse { const configurationKey: OCPPConfigurationKey[] = []; const unknownKey: string[] = []; - if (Utils.isEmptyArray(commandPayload.key)) { + if (Utils.isEmptyArray(commandPayload.key) === true) { for (const configuration of chargingStation.ocppConfiguration.configurationKey) { - if (Utils.isUndefined(configuration.visible)) { + if (Utils.isUndefined(configuration.visible) === true) { configuration.visible = true; } if (!configuration.visible) { @@ -456,10 +456,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer key ); if (keyFound) { - if (Utils.isUndefined(keyFound.visible)) { + if (Utils.isUndefined(keyFound.visible) === true) { keyFound.visible = true; } - if (!keyFound.visible) { + if (keyFound.visible === false) { continue; } configurationKey.push({ -- 2.34.1