+ private readonly workerEventDeleted = (data: ChargingStationData): void => {
+ this.uiServer.chargingStations.delete(data.stationInfo.hashId)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)!
+ --templateStatistics.added
+ templateStatistics.indexes.delete(data.stationInfo.templateIndex)
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventDeleted: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) deleted (${
+ this.numberOfAddedChargingStations
+ } added from ${this.numberOfConfiguredChargingStations} configured and ${
+ this.numberOfProvisionedChargingStations
+ } provisioned charging station(s))`
+ )
+ }
+
+ private readonly workerEventStarted = (data: ChargingStationData): void => {
+ this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ ++this.templateStatistics.get(data.stationInfo.templateName)!.started
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) started (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfAddedChargingStations} added charging station(s))`
+ )
+ }
+
+ private readonly workerEventStopped = (data: ChargingStationData): void => {
+ this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ --this.templateStatistics.get(data.stationInfo.templateName)!.started
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) stopped (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfAddedChargingStations} added charging station(s))`
+ )
+ }
+
+ private readonly workerEventUpdated = (data: ChargingStationData): void => {
+ this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ }
+
+ private readonly workerEventPerformanceStatistics = (data: Statistics): void => {
+ // eslint-disable-next-line @typescript-eslint/unbound-method
+ if (isAsyncFunction(this.storage?.storePerformanceStatistics)) {
+ (
+ this.storage.storePerformanceStatistics as (
+ performanceStatistics: Statistics
+ ) => Promise<void>
+ )(data).catch(Constants.EMPTY_FUNCTION)
+ } else {
+ (this.storage?.storePerformanceStatistics as (performanceStatistics: Statistics) => void)(
+ data
+ )
+ }
+ }
+
+ private initializeCounters (): void {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const stationTemplateUrls = Configuration.getStationTemplateUrls()!
+ if (isNotEmptyArray(stationTemplateUrls)) {
+ for (const stationTemplateUrl of stationTemplateUrls) {
+ const templateName = buildTemplateName(stationTemplateUrl.file)
+ this.templateStatistics.set(templateName, {
+ configured: stationTemplateUrl.numberOfStations,
+ provisioned: stationTemplateUrl.provisionedNumberOfStations ?? 0,
+ added: 0,
+ started: 0,
+ indexes: new Set<number>()
+ })
+ this.uiServer.chargingStationTemplates.add(templateName)
+ }
+ if (this.templateStatistics.size !== stationTemplateUrls.length) {
+ console.error(
+ chalk.red(
+ "'stationTemplateUrls' contains duplicate entries, please check your configuration"
+ )
+ )
+ exit(exitCodes.duplicateChargingStationTemplateUrls)
+ }
+ } else {
+ console.error(
+ chalk.red("'stationTemplateUrls' not defined or empty, please check your configuration")
+ )
+ exit(exitCodes.missingChargingStationsConfiguration)
+ }
+ if (
+ this.numberOfConfiguredChargingStations === 0 &&
+ Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+ .enabled !== true
+ ) {
+ console.error(
+ chalk.red(
+ "'stationTemplateUrls' has no charging station enabled and UI server is disabled, please check your configuration"
+ )
+ )
+ exit(exitCodes.noChargingStationTemplates)
+ }
+ }
+
+ public async addChargingStation (