X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FIdTagsCache.ts;h=ff5c49d9a6a2dba2fc2810b0e6a36fa54fbbb125;hb=cb60061f9e275d5b81a75c30d51771150b24f8c5;hp=7d766a40d93d6fb1eebf39bfdb873542a7cd7dba;hpb=51022aa0d811eec79514fbeb56cb9556e7168cd7;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 7d766a40..ff5c49d9 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -27,6 +27,15 @@ export class IdTagsCache { return IdTagsCache.instance; } + /** + * Get one idtag from the cache given the distribution + * Must be called after checking the cache is not an empty array + * + * @param distribution + * @param chargingStation + * @param connectorId + * @returns + */ public getIdTag( distribution: IdTagDistribution, chargingStation: ChargingStation, @@ -46,6 +55,13 @@ export class IdTagsCache { } } + /** + * Get all idtags from the cache + * Must be called after checking the cache is not an empty array + * + * @param file + * @returns + */ public getIdTags(file: string): string[] | undefined { if (this.hasIdTagsCache(file) === false) { this.setIdTagsCache(file, this.getIdTagsFromFile(file)); @@ -152,11 +168,9 @@ export class IdTagsCache { } private getIdTagsFromFile(file: string): string[] { - let idTags: string[] = []; - if (file) { + if (Utils.isNotEmptyString(file)) { try { - // Load id tags file - idTags = JSON.parse(fs.readFileSync(file, 'utf8')) as string[]; + return JSON.parse(fs.readFileSync(file, 'utf8')) as string[]; } catch (error) { ErrorUtils.handleFileException( file, @@ -165,10 +179,8 @@ export class IdTagsCache { this.logPrefix(file) ); } - } else { - logger.info(`${this.logPrefix(file)} No id tags file given`); } - return idTags; + return []; } private logPrefix = (file: string): string => {