X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FIdTagsCache.ts;h=26ef71318af3bf9cb4834c9b4e07e29faa70e1ba;hb=e843aa4048c6bfcad2d8e54763b649eda57dbcb3;hp=0b3ba285dd080777ca60de657fe2060555553536;hpb=9bf0ef23c51160abc6866ad8d07eea85e308edb8;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 0b3ba285..26ef7131 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -1,7 +1,7 @@ import { type FSWatcher, readFileSync } from 'node:fs'; import type { ChargingStation } from './ChargingStation'; -import { ChargingStationUtils } from './ChargingStationUtils'; +import { getIdTagsFile } from './ChargingStationUtils'; import { FileType, IdTagDistribution } from '../types'; import { handleFileException, @@ -46,10 +46,10 @@ export class IdTagsCache { public getIdTag( distribution: IdTagDistribution, chargingStation: ChargingStation, - connectorId: number + connectorId: number, ): string { const hashId = chargingStation.stationInfo.hashId; - const idTagsFile = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo); + const idTagsFile = getIdTagsFile(chargingStation.stationInfo); switch (distribution) { case IdTagDistribution.RANDOM: return this.getRandomIdTag(hashId, idTagsFile); @@ -85,7 +85,7 @@ export class IdTagsCache { const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId); this.idTagsCachesAddressableIndexes.set( addressableKey, - Math.floor(secureRandom() * idTags.length) + Math.floor(secureRandom() * idTags.length), ); return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)]; } @@ -97,21 +97,21 @@ export class IdTagsCache { const idTag = idTags[idTagIndex]; this.idTagsCachesAddressableIndexes.set( addressableKey, - idTagIndex === idTags.length - 1 ? 0 : idTagIndex + 1 + idTagIndex === idTags.length - 1 ? 0 : idTagIndex + 1, ); return idTag; } private getConnectorAffinityIdTag(chargingStation: ChargingStation, connectorId: number): string { - const file = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo); + const file = getIdTagsFile(chargingStation.stationInfo); const idTags = this.getIdTags(file); const addressableKey = this.getIdTagsCacheIndexesAddressableKey( file, - chargingStation.stationInfo.hashId + chargingStation.stationInfo.hashId, ); this.idTagsCachesAddressableIndexes.set( addressableKey, - (chargingStation.index - 1 + (connectorId - 1)) % idTags.length + (chargingStation.index - 1 + (connectorId - 1)) % idTags.length, ); return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)]; } @@ -132,7 +132,7 @@ export class IdTagsCache { if (isNotEmptyString(filename) && event === 'change') { try { logger.debug( - `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload` + `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`, ); this.deleteIdTagsCache(file); this.deleteIdTagsCacheIndexes(file); @@ -144,11 +144,11 @@ export class IdTagsCache { this.logPrefix(file), { throwError: false, - } + }, ); } } - } + }, ), }); } @@ -185,7 +185,7 @@ export class IdTagsCache { file, FileType.Authorization, error as NodeJS.ErrnoException, - this.logPrefix(file) + this.logPrefix(file), ); } }