From: Jérôme Benoit Date: Tue, 18 Jul 2023 18:39:04 +0000 (+0200) Subject: refactor: factor out OCPP params handling helpers X-Git-Tag: v1.2.18~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f2d5e3d9bd2e0a0e139c270ea791a5a6833c13c9;p=e-mobility-charging-stations-simulator.git refactor: factor out OCPP params handling helpers Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bca03a79..dd5bdda0 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -19,7 +19,12 @@ import { type RawData, WebSocket } from 'ws'; import { AutomaticTransactionGenerator } from './AutomaticTransactionGenerator'; import { ChargingStationWorkerBroadcastChannel } from './broadcast-channel/ChargingStationWorkerBroadcastChannel'; -import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; +import { + addConfigurationKey, + deleteConfigurationKey, + getConfigurationKey, + setConfigurationKeyValue, +} from './ChargingStationConfigurationUtils'; import { buildConnectorsMap, checkConnectorsConfiguration, @@ -212,16 +217,8 @@ export class ChargingStation { `${ this.getSupervisionUrlOcppConfiguration() && isNotEmptyString(this.getSupervisionUrlOcppKey()) && - isNotEmptyString( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.getSupervisionUrlOcppKey(), - )?.value, - ) - ? ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.getSupervisionUrlOcppKey(), - )!.value + isNotEmptyString(getConfigurationKey(this, this.getSupervisionUrlOcppKey())?.value) + ? getConfigurationKey(this, this.getSupervisionUrlOcppKey())!.value : this.configuredSupervisionUrl.href }/${this.stationInfo.chargingStationId}`, ); @@ -500,7 +497,7 @@ export class ChargingStation { } public getAuthorizeRemoteTxRequests(): boolean { - const authorizeRemoteTxRequests = ChargingStationConfigurationUtils.getConfigurationKey( + const authorizeRemoteTxRequests = getConfigurationKey( this, StandardParametersKey.AuthorizeRemoteTxRequests, ); @@ -508,7 +505,7 @@ export class ChargingStation { } public getLocalAuthListEnabled(): boolean { - const localAuthListEnabled = ChargingStationConfigurationUtils.getConfigurationKey( + const localAuthListEnabled = getConfigurationKey( this, StandardParametersKey.LocalAuthListEnabled, ); @@ -516,17 +513,11 @@ export class ChargingStation { } public getHeartbeatInterval(): number { - const HeartbeatInterval = ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.HeartbeatInterval, - ); + const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval); if (HeartbeatInterval) { return convertToInt(HeartbeatInterval.value) * 1000; } - const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.HeartBeatInterval, - ); + const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval); if (HeartBeatInterval) { return convertToInt(HeartBeatInterval.value) * 1000; } @@ -544,11 +535,7 @@ export class ChargingStation { this.getSupervisionUrlOcppConfiguration() && isNotEmptyString(this.getSupervisionUrlOcppKey()) ) { - ChargingStationConfigurationUtils.setConfigurationKeyValue( - this, - this.getSupervisionUrlOcppKey(), - url, - ); + setConfigurationKeyValue(this, this.getSupervisionUrlOcppKey(), url); } else { this.stationInfo.supervisionUrls = url; this.saveStationInfo(); @@ -771,7 +758,7 @@ export class ChargingStation { } public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined { - return ChargingStationConfigurationUtils.getConfigurationKey( + return getConfigurationKey( this, StandardParametersKey.SupportedFeatureProfiles, )?.value?.includes(featureProfile); @@ -948,10 +935,7 @@ export class ChargingStation { public getReservationOnConnectorId0Enabled(): boolean { return convertToBoolean( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.ReserveConnectorZeroSupported, - )!.value, + getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value, ); } @@ -1376,37 +1360,18 @@ export class ChargingStation { } private initializeOcppConfiguration(): void { - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.HeartbeatInterval, - ) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( - this, - StandardParametersKey.HeartbeatInterval, - '0', - ); + if (!getConfigurationKey(this, StandardParametersKey.HeartbeatInterval)) { + addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0'); } - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.HeartBeatInterval, - ) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( - this, - StandardParametersKey.HeartBeatInterval, - '0', - { visible: false }, - ); + if (!getConfigurationKey(this, StandardParametersKey.HeartBeatInterval)) { + addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false }); } if ( this.getSupervisionUrlOcppConfiguration() && isNotEmptyString(this.getSupervisionUrlOcppKey()) && - !ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey()) + !getConfigurationKey(this, this.getSupervisionUrlOcppKey()) ) { - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( this, this.getSupervisionUrlOcppKey(), this.configuredSupervisionUrl.href, @@ -1415,22 +1380,15 @@ export class ChargingStation { } else if ( !this.getSupervisionUrlOcppConfiguration() && isNotEmptyString(this.getSupervisionUrlOcppKey()) && - ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey()) + getConfigurationKey(this, this.getSupervisionUrlOcppKey()) ) { - ChargingStationConfigurationUtils.deleteConfigurationKey( - this, - this.getSupervisionUrlOcppKey(), - { save: false }, - ); + deleteConfigurationKey(this, this.getSupervisionUrlOcppKey(), { save: false }); } if ( isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) && - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.stationInfo.amperageLimitationOcppKey!, - ) + !getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) ) { - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( this, this.stationInfo.amperageLimitationOcppKey!, ( @@ -1438,43 +1396,28 @@ export class ChargingStation { ).toString(), ); } - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.SupportedFeatureProfiles, - ) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( + if (!getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)) { + addConfigurationKey( this, StandardParametersKey.SupportedFeatureProfiles, `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`, ); } - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( this, StandardParametersKey.NumberOfConnectors, this.getNumberOfConnectors().toString(), { readonly: true }, { overwrite: true }, ); - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.MeterValuesSampledData, - ) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( + if (!getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData)) { + addConfigurationKey( this, StandardParametersKey.MeterValuesSampledData, MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER, ); } - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.ConnectorPhaseRotation, - ) - ) { + if (!getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation)) { const connectorsPhaseRotation: string[] = []; if (this.hasEvses) { for (const evseStatus of this.evses.values()) { @@ -1491,47 +1434,25 @@ export class ChargingStation { ); } } - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( this, StandardParametersKey.ConnectorPhaseRotation, connectorsPhaseRotation.toString(), ); } - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.AuthorizeRemoteTxRequests, - ) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( - this, - StandardParametersKey.AuthorizeRemoteTxRequests, - 'true', - ); + if (!getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests)) { + addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true'); } if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.LocalAuthListEnabled, - ) && - ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.SupportedFeatureProfiles, - )?.value?.includes(SupportedFeatureProfiles.LocalAuthListManagement) - ) { - ChargingStationConfigurationUtils.addConfigurationKey( - this, - StandardParametersKey.LocalAuthListEnabled, - 'false', - ); - } - if ( - !ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.ConnectionTimeOut, + !getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) && + getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)?.value?.includes( + SupportedFeatureProfiles.LocalAuthListManagement, ) ) { - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false'); + } + if (!getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) { + addConfigurationKey( this, StandardParametersKey.ConnectionTimeOut, Constants.DEFAULT_CONNECTION_TIMEOUT.toString(), @@ -2167,19 +2088,10 @@ export class ChargingStation { // 0 for disabling private getConnectionTimeout(): number { - if ( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.ConnectionTimeOut, - ) - ) { + if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) { return ( - parseInt( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.ConnectionTimeOut, - )!.value!, - ) ?? Constants.DEFAULT_CONNECTION_TIMEOUT + parseInt(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value!) ?? + Constants.DEFAULT_CONNECTION_TIMEOUT ); } return Constants.DEFAULT_CONNECTION_TIMEOUT; @@ -2222,17 +2134,11 @@ export class ChargingStation { private getAmperageLimitation(): number | undefined { if ( isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) && - ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.stationInfo.amperageLimitationOcppKey!, - ) + getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) ) { return ( convertToInt( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.stationInfo.amperageLimitationOcppKey!, - )?.value, + getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)?.value, ) / getAmperageLimitationUnitDivider(this.stationInfo) ); } @@ -2351,16 +2257,11 @@ export class ChargingStation { } private startWebSocketPing(): void { - const webSocketPingInterval: number = ChargingStationConfigurationUtils.getConfigurationKey( + const webSocketPingInterval: number = getConfigurationKey( this, StandardParametersKey.WebSocketPingInterval, ) - ? convertToInt( - ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.WebSocketPingInterval, - )?.value, - ) + ? convertToInt(getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value) : 0; if (webSocketPingInterval > 0 && !this.webSocketPingSetInterval) { this.webSocketPingSetInterval = setInterval(() => { diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index b56411e3..39606b66 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -16,110 +16,96 @@ interface AddConfigurationKeyParams { save?: boolean; } -export class ChargingStationConfigurationUtils { - private constructor() { - // This is intentional - } - - public static getConfigurationKey( - chargingStation: ChargingStation, - key: ConfigurationKeyType, - caseInsensitive = false, - ): ConfigurationKey | undefined { - return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => { - if (caseInsensitive) { - return configElement.key.toLowerCase() === key.toLowerCase(); - } - return configElement.key === key; - }); - } +export const getConfigurationKey = ( + chargingStation: ChargingStation, + key: ConfigurationKeyType, + caseInsensitive = false, +): ConfigurationKey | undefined => { + return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => { + if (caseInsensitive) { + return configElement.key.toLowerCase() === key.toLowerCase(); + } + return configElement.key === key; + }); +}; - public static addConfigurationKey( - chargingStation: ChargingStation, - key: ConfigurationKeyType, - value: string, - options: ConfigurationKeyOptions = { +export const addConfigurationKey = ( + chargingStation: ChargingStation, + key: ConfigurationKeyType, + value: string, + options: ConfigurationKeyOptions = { + readonly: false, + visible: true, + reboot: false, + }, + params: AddConfigurationKeyParams = { overwrite: false, save: false }, +): void => { + options = { + ...{ readonly: false, visible: true, reboot: false, }, - params: AddConfigurationKeyParams = { overwrite: false, save: false }, - ): void { - options = { - ...{ - readonly: false, - visible: true, - reboot: false, - }, - ...options, - }; - params = { ...{ overwrite: false, save: false }, ...params }; - let keyFound = ChargingStationConfigurationUtils.getConfigurationKey(chargingStation, key); - if (keyFound && params?.overwrite) { - ChargingStationConfigurationUtils.deleteConfigurationKey(chargingStation, keyFound.key, { - save: false, - }); - keyFound = undefined; - } - if (!keyFound) { - chargingStation.ocppConfiguration?.configurationKey?.push({ - key, - readonly: options.readonly!, - value, - visible: options.visible, - reboot: options.reboot, - }); - params?.save && chargingStation.saveOcppConfiguration(); - } else { - logger.error( - `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`, - keyFound, - ); - } + ...options, + }; + params = { ...{ overwrite: false, save: false }, ...params }; + let keyFound = getConfigurationKey(chargingStation, key); + if (keyFound && params?.overwrite) { + deleteConfigurationKey(chargingStation, keyFound.key, { + save: false, + }); + keyFound = undefined; } - - public static setConfigurationKeyValue( - chargingStation: ChargingStation, - key: ConfigurationKeyType, - value: string, - caseInsensitive = false, - ): void { - const keyFound = ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, + if (!keyFound) { + chargingStation.ocppConfiguration?.configurationKey?.push({ key, - caseInsensitive, + readonly: options.readonly!, + value, + visible: options.visible, + reboot: options.reboot, + }); + params?.save && chargingStation.saveOcppConfiguration(); + } else { + logger.error( + `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`, + keyFound, ); - if (keyFound) { - chargingStation.ocppConfiguration!.configurationKey![ - chargingStation.ocppConfiguration!.configurationKey!.indexOf(keyFound) - ].value = value; - chargingStation.saveOcppConfiguration(); - } else { - logger.error( - `${chargingStation.logPrefix()} Trying to set a value on a non existing configuration key: %j`, - { key, value }, - ); - } } +}; - public static deleteConfigurationKey( - chargingStation: ChargingStation, - key: ConfigurationKeyType, - params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false }, - ): ConfigurationKey[] | undefined { - params = { ...{ save: true, caseInsensitive: false }, ...params }; - const keyFound = ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - key, - params?.caseInsensitive, +export const setConfigurationKeyValue = ( + chargingStation: ChargingStation, + key: ConfigurationKeyType, + value: string, + caseInsensitive = false, +): void => { + const keyFound = getConfigurationKey(chargingStation, key, caseInsensitive); + if (keyFound) { + chargingStation.ocppConfiguration!.configurationKey![ + chargingStation.ocppConfiguration!.configurationKey!.indexOf(keyFound) + ].value = value; + chargingStation.saveOcppConfiguration(); + } else { + logger.error( + `${chargingStation.logPrefix()} Trying to set a value on a non existing configuration key: %j`, + { key, value }, ); - if (keyFound) { - const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice( - chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound), - 1, - ); - params?.save && chargingStation.saveOcppConfiguration(); - return deletedConfigurationKey; - } } -} +}; + +export const deleteConfigurationKey = ( + chargingStation: ChargingStation, + key: ConfigurationKeyType, + params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false }, +): ConfigurationKey[] | undefined => { + params = { ...{ save: true, caseInsensitive: false }, ...params }; + const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive); + if (keyFound) { + const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice( + chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound), + 1, + ); + params?.save && chargingStation.saveOcppConfiguration(); + return deletedConfigurationKey; + } +}; diff --git a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts index 84d6961e..bb484be7 100644 --- a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts @@ -36,7 +36,7 @@ import { } from '../../types'; import { Constants, convertToInt, isEmptyObject, isNullOrUndefined, logger } from '../../utils'; import type { ChargingStation } from '../ChargingStation'; -import { ChargingStationConfigurationUtils } from '../ChargingStationConfigurationUtils'; +import { getConfigurationKey } from '../ChargingStationConfigurationUtils'; import { OCPP16ServiceUtils } from '../ocpp'; const moduleName = 'ChargingStationWorkerBroadcastChannel'; @@ -173,11 +173,10 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne [ BroadcastChannelProcedureName.METER_VALUES, async (requestPayload?: BroadcastChannelRequestPayload) => { - const configuredMeterValueSampleInterval = - ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - StandardParametersKey.MeterValueSampleInterval, - ); + const configuredMeterValueSampleInterval = getConfigurationKey( + chargingStation, + StandardParametersKey.MeterValueSampleInterval, + ); return this.chargingStation.ocppRequestService.requestHandler< MeterValuesRequest, MeterValuesResponse diff --git a/src/charging-station/index.ts b/src/charging-station/index.ts index 49ae434a..7e992fe2 100644 --- a/src/charging-station/index.ts +++ b/src/charging-station/index.ts @@ -1,4 +1,8 @@ export { Bootstrap } from './Bootstrap'; export type { ChargingStation } from './ChargingStation'; -export { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; +export { + addConfigurationKey, + getConfigurationKey, + setConfigurationKeyValue, +} from './ChargingStationConfigurationUtils'; export { getIdTagsFile, checkChargingStation, resetConnectorStatus } from './ChargingStationUtils'; diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 5fa160c3..163b006f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -12,8 +12,9 @@ import { OCPP16Constants } from './OCPP16Constants'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import { type ChargingStation, - ChargingStationConfigurationUtils, checkChargingStation, + getConfigurationKey, + setConfigurationKeyValue, } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { @@ -512,11 +513,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } } else if (isNotEmptyArray(commandPayload.key) === true) { for (const key of commandPayload.key!) { - const keyFound = ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - key, - true, - ); + const keyFound = getConfigurationKey(chargingStation, key, true); if (keyFound) { if (isUndefined(keyFound.visible) === true) { keyFound.visible = true; @@ -544,22 +541,13 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingStation: ChargingStation, commandPayload: ChangeConfigurationRequest, ): ChangeConfigurationResponse { - const keyToChange = ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - commandPayload.key, - true, - ); + const keyToChange = getConfigurationKey(chargingStation, commandPayload.key, true); if (keyToChange?.readonly === true) { return OCPP16Constants.OCPP_CONFIGURATION_RESPONSE_REJECTED; } else if (keyToChange?.readonly === false) { let valueChanged = false; if (keyToChange.value !== commandPayload.value) { - ChargingStationConfigurationUtils.setConfigurationKeyValue( - chargingStation, - commandPayload.key, - commandPayload.value, - true, - ); + setConfigurationKeyValue(chargingStation, commandPayload.key, commandPayload.value, true); valueChanged = true; } let triggerHeartbeatRestart = false; @@ -568,7 +556,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StandardParametersKey.HeartBeatInterval && valueChanged ) { - ChargingStationConfigurationUtils.setConfigurationKeyValue( + setConfigurationKeyValue( chargingStation, OCPP16StandardParametersKey.HeartbeatInterval, commandPayload.value, @@ -580,7 +568,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StandardParametersKey.HeartbeatInterval && valueChanged ) { - ChargingStationConfigurationUtils.setConfigurationKeyValue( + setConfigurationKeyValue( chargingStation, OCPP16StandardParametersKey.HeartBeatInterval, commandPayload.value, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 02c03140..78c2cedb 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -7,7 +7,8 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import { type ChargingStation, - ChargingStationConfigurationUtils, + addConfigurationKey, + getConfigurationKey, resetConnectorStatus, } from '../../../charging-station'; import { OCPPError } from '../../../exception'; @@ -407,14 +408,14 @@ export class OCPP16ResponseService extends OCPPResponseService { payload: OCPP16BootNotificationResponse, ): void { if (payload.status === RegistrationStatusEnumType.ACCEPTED) { - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( chargingStation, OCPP16StandardParametersKey.HeartbeatInterval, payload.interval.toString(), {}, { overwrite: true, save: true }, ); - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( chargingStation, OCPP16StandardParametersKey.HeartBeatInterval, payload.interval.toString(), @@ -655,11 +656,10 @@ export class OCPP16ResponseService extends OCPPResponseService { if (chargingStation.stationInfo.powerSharedByConnectors) { ++chargingStation.powerDivider; } - const configuredMeterValueSampleInterval = - ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - OCPP16StandardParametersKey.MeterValueSampleInterval, - ); + const configuredMeterValueSampleInterval = getConfigurationKey( + chargingStation, + OCPP16StandardParametersKey.MeterValueSampleInterval, + ); chargingStation.startMeterValues( transactionConnectorId, configuredMeterValueSampleInterval diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 47271946..81dca3a4 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -3,7 +3,7 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; -import { type ChargingStation, ChargingStationConfigurationUtils } from '../../../charging-station'; +import { type ChargingStation, addConfigurationKey } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { ErrorType, @@ -168,7 +168,7 @@ export class OCPP20ResponseService extends OCPPResponseService { payload: OCPP20BootNotificationResponse, ): void { if (payload.status === RegistrationStatusEnumType.ACCEPTED) { - ChargingStationConfigurationUtils.addConfigurationKey( + addConfigurationKey( chargingStation, OCPP20OptionalVariableName.HeartbeatInterval, payload.interval.toString(), diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 16d83ee9..5dbe2fb4 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -7,7 +7,7 @@ import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv'; import { OCPP16Constants } from './1.6/OCPP16Constants'; import { OCPP20Constants } from './2.0/OCPP20Constants'; import { OCPPConstants } from './OCPPConstants'; -import { type ChargingStation, ChargingStationConfigurationUtils } from '../../charging-station'; +import { type ChargingStation, getConfigurationKey } from '../../charging-station'; import { BaseError } from '../../exception'; import { ChargePointErrorCode, @@ -308,7 +308,7 @@ export class OCPPServiceUtils { } if ( measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER && - ChargingStationConfigurationUtils.getConfigurationKey( + getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData, )?.value?.includes(measurand) === false @@ -340,7 +340,7 @@ export class OCPPServiceUtils { phase && sampledValueTemplates[index]?.phase === phase && sampledValueTemplates[index]?.measurand === measurand && - ChargingStationConfigurationUtils.getConfigurationKey( + getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData, )?.value?.includes(measurand) === true @@ -350,7 +350,7 @@ export class OCPPServiceUtils { !phase && !sampledValueTemplates[index].phase && sampledValueTemplates[index]?.measurand === measurand && - ChargingStationConfigurationUtils.getConfigurationKey( + getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData, )?.value?.includes(measurand) === true