From: Jérôme Benoit Date: Mon, 5 Sep 2022 23:48:33 +0000 (+0200) Subject: Add types to OCPP configuration key handling code X-Git-Tag: v1.1.72~19 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a723e7e9df355545fc6a41bdcbb9debfae22db5f;p=e-mobility-charging-stations-simulator.git Add types to OCPP configuration key handling code Signed-off-by: Jérôme Benoit --- 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({