From: Jérôme Benoit Date: Thu, 27 Jul 2023 15:23:19 +0000 (+0200) Subject: refactor: factor out feature profile test X-Git-Tag: v1.2.20~113 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d8093be156ab575dbd44546ef4646a6338a27358;p=e-mobility-charging-stations-simulator.git refactor: factor out feature profile test Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 3be6dfd9..57fbac97 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -43,6 +43,7 @@ import { getIdTagsFile, getMaxNumberOfEvses, getPhaseRotationValue, + hasFeatureProfile, initializeConnectorsMapStatus, propagateSerialNumber, stationTemplateToStationInfo, @@ -668,7 +669,7 @@ export class ChargingStation { if (this.getEnableStatistics() === true) { this.performanceStatistics?.start(); } - if (this.hasFeatureProfile(SupportedFeatureProfiles.Reservation)) { + if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) { this.startReservationExpirationSetInterval(); } this.openWSConnection(); @@ -731,7 +732,7 @@ export class ChargingStation { if (this.getEnableStatistics() === true) { this.performanceStatistics?.stop(); } - if (this.hasFeatureProfile(SupportedFeatureProfiles.Reservation)) { + if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) { this.stopReservationExpirationSetInterval(); } this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash); @@ -763,13 +764,6 @@ export class ChargingStation { } } - public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined { - return getConfigurationKey( - this, - StandardParametersKey.SupportedFeatureProfiles, - )?.value?.includes(featureProfile); - } - public bufferMessage(message: string): void { this.messageBuffer.add(message); } @@ -973,8 +967,6 @@ export class ChargingStation { const connector = this.getConnectorStatus(reservation.connectorId)!; switch (reason) { case ReservationTerminationReason.CONNECTOR_STATE_CHANGED: - delete connector.reservation; - break; case ReservationTerminationReason.TRANSACTION_STARTED: delete connector.reservation; break; diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 6c273246..2be30929 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -19,6 +19,7 @@ import { } from 'date-fns'; import type { ChargingStation } from './ChargingStation'; +import { getConfigurationKey } from './ChargingStationConfigurationUtils'; import { BaseError } from '../exception'; import { AmpereUnits, @@ -41,6 +42,8 @@ import { type OCPP20BootNotificationRequest, OCPPVersion, RecurrencyKindType, + StandardParametersKey, + SupportedFeatureProfiles, Voltage, } from '../types'; import { @@ -449,6 +452,16 @@ export const propagateSerialNumber = ( : stationInfoDst?.meterSerialNumber && delete stationInfoDst.meterSerialNumber; }; +export const hasFeatureProfile = ( + chargingStation: ChargingStation, + featureProfile: SupportedFeatureProfiles, +): boolean | undefined => { + return getConfigurationKey( + chargingStation, + StandardParametersKey.SupportedFeatureProfiles, + )?.value?.includes(featureProfile); +}; + export const getAmperageLimitationUnitDivider = (stationInfo: ChargingStationInfo): number => { let unitDivider = 1; switch (stationInfo.amperageLimitationUnit) { diff --git a/src/charging-station/index.ts b/src/charging-station/index.ts index 7e992fe2..2823c1e2 100644 --- a/src/charging-station/index.ts +++ b/src/charging-station/index.ts @@ -5,4 +5,9 @@ export { getConfigurationKey, setConfigurationKeyValue, } from './ChargingStationConfigurationUtils'; -export { getIdTagsFile, checkChargingStation, resetConnectorStatus } from './ChargingStationUtils'; +export { + getIdTagsFile, + checkChargingStation, + resetConnectorStatus, + hasFeatureProfile, +} from './ChargingStationUtils'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index d0afb367..7f065d30 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -2,7 +2,7 @@ import type { JSONSchemaType } from 'ajv'; -import { type ChargingStation, getIdTagsFile } from '../../../charging-station'; +import { type ChargingStation, getIdTagsFile, hasFeatureProfile } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { type ClearChargingProfileRequest, @@ -55,7 +55,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { featureProfile: OCPP16SupportedFeatureProfiles, command: OCPP16RequestCommand | OCPP16IncomingRequestCommand, ): boolean { - if (!chargingStation.hasFeatureProfile(featureProfile)) { + if (!hasFeatureProfile(chargingStation, featureProfile)) { logger.warn( `${chargingStation.logPrefix()} Trying to '${command}' without '${featureProfile}' feature enabled in ${ OCPP16StandardParametersKey.SupportedFeatureProfiles