// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
import crypto from 'node:crypto';
-import path from 'path';
-import { URL } from 'url';
+import fs from 'node:fs';
+import path from 'node:path';
+import { URL } from 'node:url';
import { parentPort } from 'worker_threads';
import merge from 'just-merge';
import {
type ChargingStationTemplate,
CurrentType,
+ type FirmwareUpgrade,
PowerUnits,
type WsOptions,
} from '../types/ChargingStationTemplate';
);
}
- public logPrefix(): string {
+ public logPrefix = (): string => {
return Utils.logPrefix(
` ${
- this?.stationInfo?.chargingStationId ??
- ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile())
+ (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId) &&
+ this?.stationInfo?.chargingStationId) ??
+ ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile()) ??
+ ''
} |`
);
- }
+ };
public hasAuthorizedTags(): boolean {
- return !Utils.isEmptyArray(
+ return Utils.isNotEmptyArray(
this.authorizedTagsCache.getAuthorizedTags(
ChargingStationUtils.getAuthorizationFile(this.stationInfo)
)
this.openWSConnection();
// Monitor charging station template file
this.templateFileWatcher = FileUtils.watchJsonFile(
- this.logPrefix(),
- FileType.ChargingStationTemplate,
this.templateFile,
- null,
+ FileType.ChargingStationTemplate,
+ this.logPrefix(),
+ undefined,
(event, filename): void => {
- if (!Utils.isEmptyString(filename) && event === 'change') {
+ if (Utils.isNotEmptyString(filename) && event === 'change') {
try {
logger.debug(
`${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
this
);
- if (!Utils.isEmptyArray(connectorIds)) {
+ if (Utils.isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.startConnector(connectorId);
}
}
public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
- if (!Utils.isEmptyArray(connectorIds)) {
+ if (Utils.isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.stopConnector(connectorId);
}
}
} catch (error) {
FileUtils.handleFileException(
- this.logPrefix(),
- FileType.ChargingStationTemplate,
this.templateFile,
- error as NodeJS.ErrnoException
+ FileType.ChargingStationTemplate,
+ error as NodeJS.ErrnoException,
+ this.logPrefix()
);
}
return template;
);
stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
ChargingStationUtils.createSerialNumber(stationTemplate, stationInfo);
- if (!Utils.isEmptyArray(stationTemplate?.power)) {
+ if (Utils.isNotEmptyArray(stationTemplate?.power)) {
stationTemplate.power = stationTemplate.power as number[];
const powerArrayRandomIndex = Math.floor(Utils.secureRandom() * stationTemplate.power.length);
stationInfo.maximumPower =
stationInfo.firmwareVersionPattern =
stationTemplate?.firmwareVersionPattern ?? Constants.SEMVER_PATTERN;
if (
- !Utils.isEmptyString(stationInfo.firmwareVersion) &&
+ Utils.isNotEmptyString(stationInfo.firmwareVersion) &&
new RegExp(stationInfo.firmwareVersionPattern).test(stationInfo.firmwareVersion) === false
) {
logger.warn(
} does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
);
}
- stationInfo.firmwareUpgrade = merge(
+ stationInfo.firmwareUpgrade = merge<FirmwareUpgrade>(
{
+ versionUpgrade: {
+ step: 1,
+ },
reset: true,
},
stationTemplate?.firmwareUpgrade ?? {}
}
if (
this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
- !Utils.isEmptyString(this.stationInfo.firmwareVersion) &&
- !Utils.isEmptyString(this.stationInfo.firmwareVersionPattern)
+ Utils.isNotEmptyString(this.stationInfo.firmwareVersion) &&
+ Utils.isNotEmptyString(this.stationInfo.firmwareVersionPattern)
) {
- const versionStep = this.stationInfo.firmwareUpgrade?.versionUpgrade?.step ?? 1;
const patternGroup: number | undefined =
this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
this.stationInfo.firmwareVersion?.split('.').length;
?.slice(1, patternGroup + 1);
const patchLevelIndex = match.length - 1;
match[patchLevelIndex] = (
- Utils.convertToInt(match[patchLevelIndex]) + versionStep
+ Utils.convertToInt(match[patchLevelIndex]) +
+ this.stationInfo.firmwareUpgrade?.versionUpgrade?.step
).toString();
this.stationInfo.firmwareVersion = match?.join('.');
}
);
}
if (
- !Utils.isEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
+ Utils.isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
!ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey
}
} catch (error) {
FileUtils.handleFileException(
- this.logPrefix(),
- FileType.ChargingStationConfiguration,
this.configurationFile,
- error as NodeJS.ErrnoException
+ FileType.ChargingStationConfiguration,
+ error as NodeJS.ErrnoException,
+ this.logPrefix()
);
}
}
}
} catch (error) {
FileUtils.handleFileException(
- this.logPrefix(),
- FileType.ChargingStationConfiguration,
this.configurationFile,
- error as NodeJS.ErrnoException
+ FileType.ChargingStationConfiguration,
+ error as NodeJS.ErrnoException,
+ this.logPrefix()
);
}
} else {
private getAmperageLimitation(): number | undefined {
if (
- !Utils.isEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
+ Utils.isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey
private getConfiguredSupervisionUrl(): URL {
const supervisionUrls = this.stationInfo?.supervisionUrls ?? Configuration.getSupervisionUrls();
- if (!Utils.isEmptyArray(supervisionUrls)) {
+ if (Utils.isNotEmptyArray(supervisionUrls)) {
switch (Configuration.getSupervisionUrlDistribution()) {
case SupervisionUrlDistribution.ROUND_ROBIN:
// FIXME