}
public logPrefix = (): string => {
- return logPrefix(
- ` ${
- (isNotEmptyString(this?.stationInfo?.chargingStationId)
- ? this?.stationInfo?.chargingStationId
- : getChargingStationId(this.index, this.getTemplateFromFile()!)) ??
- 'Error at building log prefix'
- } |`,
- );
+ if (isNotEmptyString(this?.stationInfo?.chargingStationId)) {
+ return logPrefix(` ${this?.stationInfo?.chargingStationId} |`);
+ }
+ let stationTemplate: ChargingStationTemplate | undefined;
+ try {
+ stationTemplate = JSON.parse(
+ readFileSync(this.templateFile, 'utf8'),
+ ) as ChargingStationTemplate;
+ } catch {
+ stationTemplate = undefined;
+ }
+ return logPrefix(` ${getChargingStationId(this.index, stationTemplate)} |`);
};
public hasIdTags(): boolean {
export const getChargingStationId = (
index: number,
- stationTemplate: ChargingStationTemplate,
+ stationTemplate: ChargingStationTemplate | undefined,
): string => {
+ if (isUndefined(stationTemplate)) {
+ return "Unknown 'chargingStationId'";
+ }
// In case of multiple instances: add instance index to charging station id
const instanceIndex = env.CF_INSTANCE_INDEX ?? 0;
const idSuffix = stationTemplate?.nameSuffix ?? '';
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}`;
};