X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FHelpers.ts;h=492d26aa10dbeb5a5d028e1a7d6d111c291ac368;hb=de7b9e0583275225509c099f75a2801371da54d0;hp=ce0ba3e373cc02cc588615e29f02ebee3eea615a;hpb=c1f16afd333f0fc8a6a02b9baa0aff23dbd18580;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index ce0ba3e3..492d26aa 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url'; import chalk from 'chalk'; import { + type Interval, addDays, addSeconds, addWeeks, @@ -17,9 +18,9 @@ import { isDate, isPast, isWithinInterval, - maxTime, toDate, } from 'date-fns'; +import { maxTime } from 'date-fns/constants'; import type { ChargingStation } from './ChargingStation'; import { getConfigurationKey } from './ConfigurationKeyUtils'; @@ -33,6 +34,7 @@ import { ChargingProfileKindType, ChargingRateUnitType, type ChargingSchedulePeriod, + type ChargingStationConfiguration, type ChargingStationInfo, type ChargingStationTemplate, ChargingStationWorkerMessageEvents, @@ -76,7 +78,7 @@ export const getChargingStationId = ( index: number, stationTemplate: ChargingStationTemplate | undefined, ): string => { - if (isUndefined(stationTemplate)) { + if (stationTemplate === undefined) { return "Unknown 'chargingStationId'"; } // In case of multiple instances: add instance index to charging station id @@ -85,7 +87,7 @@ export const getChargingStationId = ( const idStr = `000000000${index.toString()}`; return stationTemplate?.fixedName ? stationTemplate.baseName - : `${stationTemplate?.baseName}-${instanceIndex.toString()}${idStr.substring( + : `${stationTemplate.baseName}-${instanceIndex.toString()}${idStr.substring( idStr.length - 4, )}${idSuffix}`; }; @@ -253,6 +255,23 @@ export const checkTemplate = ( } }; +export const checkConfiguration = ( + stationConfiguration: ChargingStationConfiguration | undefined, + logPrefix: string, + configurationFile: string, +): void => { + if (isNullOrUndefined(stationConfiguration)) { + const errorMsg = `Failed to read charging station configuration file ${configurationFile}`; + logger.error(`${logPrefix} ${errorMsg}`); + throw new BaseError(errorMsg); + } + if (isEmptyObject(stationConfiguration!)) { + const errorMsg = `Empty charging station configuration from file ${configurationFile}`; + logger.error(`${logPrefix} ${errorMsg}`); + throw new BaseError(errorMsg); + } +}; + export const checkConnectorsConfiguration = ( stationTemplate: ChargingStationTemplate, logPrefix: string,