X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FConfigurationKeyUtils.ts;h=075a497988ae2f5375a665568be67bd7fe8dae82;hb=a974c8e4b8a98c9450be49546a77be0d03e9f512;hp=044c09230b85c9e1ee01ecd41b8fe37be2cc5183;hpb=66a7748ddeda8c94d7562a1ce58d440319654a4c;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ConfigurationKeyUtils.ts b/src/charging-station/ConfigurationKeyUtils.ts index 044c0923..075a4979 100644 --- a/src/charging-station/ConfigurationKeyUtils.ts +++ b/src/charging-station/ConfigurationKeyUtils.ts @@ -21,7 +21,7 @@ export const getConfigurationKey = ( key: ConfigurationKeyType, caseInsensitive = false ): ConfigurationKey | undefined => { - return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => { + return chargingStation.ocppConfiguration?.configurationKey?.find(configElement => { if (caseInsensitive) { return configElement.key.toLowerCase() === key.toLowerCase() } @@ -46,13 +46,13 @@ export const addConfigurationKey = ( } params = { ...{ overwrite: false, save: false }, ...params } let keyFound = getConfigurationKey(chargingStation, key) - if (keyFound !== undefined && params?.overwrite === true) { + if (keyFound != null && params.overwrite === true) { deleteConfigurationKey(chargingStation, keyFound.key, { save: false }) keyFound = undefined } - if (keyFound === undefined) { + if (keyFound == null) { chargingStation.ocppConfiguration?.configurationKey?.push({ key, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -61,7 +61,7 @@ export const addConfigurationKey = ( visible: options.visible, reboot: options.reboot }) - params?.save === true && chargingStation.saveOcppConfiguration() + params.save === true && chargingStation.saveOcppConfiguration() } else { logger.error( `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`, @@ -75,9 +75,9 @@ export const setConfigurationKeyValue = ( key: ConfigurationKeyType, value: string, caseInsensitive = false -): void => { +): ConfigurationKey | undefined => { const keyFound = getConfigurationKey(chargingStation, key, caseInsensitive) - if (keyFound !== undefined) { + if (keyFound != null) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion chargingStation.ocppConfiguration!.configurationKey![ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -90,6 +90,7 @@ export const setConfigurationKeyValue = ( { key, value } ) } + return keyFound } export const deleteConfigurationKey = ( @@ -98,13 +99,13 @@ export const deleteConfigurationKey = ( params?: DeleteConfigurationKeyParams ): ConfigurationKey[] | undefined => { params = { ...{ save: true, caseInsensitive: false }, ...params } - const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive) - if (keyFound !== undefined) { + const keyFound = getConfigurationKey(chargingStation, key, params.caseInsensitive) + if (keyFound != null) { const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice( chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound), 1 ) - params?.save === true && chargingStation.saveOcppConfiguration() + params.save === true && chargingStation.saveOcppConfiguration() return deletedConfigurationKey } }