public getVoltageOut(stationInfo?: ChargingStationInfo): number | undefined {
const defaultVoltageOut = ChargingStationUtils.getDefaultVoltageOut(
this.getCurrentOutType(stationInfo),
- this.templateFile,
- this.logPrefix()
+ this.logPrefix(),
+ this.templateFile
);
const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo;
return !Utils.isUndefined(localStationInfo.voltageOut)
private getStationInfoFromTemplate(): ChargingStationInfo {
const stationTemplate: ChargingStationTemplate | undefined = this.getTemplateFromFile();
- if (Utils.isNullOrUndefined(stationTemplate)) {
- const errorMsg = `Failed to read charging station template file ${this.templateFile}`;
- logger.error(`${this.logPrefix()} ${errorMsg}`);
- throw new BaseError(errorMsg);
- }
- if (Utils.isEmptyObject(stationTemplate)) {
- const errorMsg = `Empty charging station information from template file ${this.templateFile}`;
- logger.error(`${this.logPrefix()} ${errorMsg}`);
- throw new BaseError(errorMsg);
- }
+ ChargingStationUtils.checkTemplateFile(stationTemplate, this.logPrefix(), this.templateFile);
ChargingStationUtils.warnTemplateKeysDeprecation(
- this.templateFile,
stationTemplate,
- this.logPrefix()
+ this.logPrefix(),
+ this.templateFile
);
+ if (stationTemplate?.Connectors) {
+ ChargingStationUtils.checkConnectorsConfiguration(
+ stationTemplate,
+ this.logPrefix(),
+ this.templateFile
+ );
+ }
const stationInfo: ChargingStationInfo =
ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);
? stationTemplate.resetTime * 1000
: Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
- if (stationInfo?.Connectors) {
- ChargingStationUtils.checkConnectorsConfiguration(
- stationInfo,
- this.templateFile,
- this.logPrefix()
- );
- }
- delete stationInfo?.Connectors;
- delete stationInfo?.Evses;
return stationInfo;
}
private initialize(): void {
const stationTemplate = this.getTemplateFromFile();
- if (Utils.isNullOrUndefined(stationTemplate)) {
- const errorMsg = `Failed to read charging station template file ${this.templateFile}`;
- logger.error(`${this.logPrefix()} ${errorMsg}`);
- throw new BaseError(errorMsg);
- }
+ ChargingStationUtils.checkTemplateFile(stationTemplate, this.logPrefix(), this.templateFile);
this.configurationFile = path.join(
path.dirname(this.templateFile.replace('station-templates', 'configurations')),
`${ChargingStationUtils.getHashId(this.index, stationTemplate)}.json`
const { configuredMaxConnectors, templateMaxConnectors, templateMaxAvailableConnectors } =
ChargingStationUtils.checkConnectorsConfiguration(
stationTemplate,
- this.templateFile,
- this.logPrefix()
+ this.logPrefix(),
+ this.templateFile
);
const connectorsConfigHash = crypto
.createHash(Constants.DEFAULT_HASH_ALGORITHM)
return connectorBootStatus;
}
+ public static checkTemplateFile(
+ stationTemplate: ChargingStationTemplate,
+ logPrefix: string,
+ templateFile: string
+ ) {
+ if (Utils.isNullOrUndefined(stationTemplate)) {
+ const errorMsg = `Failed to read charging station template file ${templateFile}`;
+ logger.error(`${logPrefix} ${errorMsg}`);
+ throw new BaseError(errorMsg);
+ }
+ if (Utils.isEmptyObject(stationTemplate)) {
+ const errorMsg = `Empty charging station information from template file ${templateFile}`;
+ logger.error(`${logPrefix} ${errorMsg}`);
+ throw new BaseError(errorMsg);
+ }
+ }
+
public static checkConnectorsConfiguration(
- stationTemplate: ChargingStationTemplate | ChargingStationInfo,
- templateFile: string,
- logPrefix: string
+ stationTemplate: ChargingStationTemplate,
+ logPrefix: string,
+ templateFile: string
): {
configuredMaxConnectors: number;
templateMaxConnectors: number;
ChargingStationUtils.getConfiguredNumberOfConnectors(stationTemplate);
ChargingStationUtils.checkConfiguredMaxConnectors(
configuredMaxConnectors,
- templateFile,
- logPrefix
+ logPrefix,
+ templateFile
);
const templateMaxConnectors = ChargingStationUtils.getMaxNumberOfConnectors(
stationTemplate.Connectors
);
- ChargingStationUtils.checkTemplateMaxConnectors(templateMaxConnectors, templateFile, logPrefix);
+ ChargingStationUtils.checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile);
const templateMaxAvailableConnectors = stationTemplate?.Connectors[0]
? templateMaxConnectors - 1
: templateMaxConnectors;
}
public static warnTemplateKeysDeprecation(
- templateFile: string,
stationTemplate: ChargingStationTemplate,
- logPrefix: string
+ logPrefix: string,
+ templateFile: string
) {
const templateKeys: { key: string; deprecatedKey: string }[] = [
{ key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
ChargingStationUtils.warnDeprecatedTemplateKey(
stationTemplate,
templateKey.deprecatedKey,
- templateFile,
logPrefix,
+ templateFile,
`Use '${templateKey.key}' instead`
);
ChargingStationUtils.convertDeprecatedTemplateKey(
stationTemplate = Utils.cloneObject(stationTemplate);
delete stationTemplate.power;
delete stationTemplate.powerUnit;
+ delete stationTemplate?.Connectors;
+ delete stationTemplate?.Evses;
delete stationTemplate.Configuration;
delete stationTemplate.AutomaticTransactionGenerator;
delete stationTemplate.chargeBoxSerialNumberPrefix;
public static getDefaultVoltageOut(
currentType: CurrentType,
- templateFile: string,
- logPrefix: string
+ logPrefix: string,
+ templateFile: string
): Voltage {
const errorMsg = `Unknown ${currentType} currentOutType in template file ${templateFile}, cannot define default voltage out`;
let defaultVoltageOut: number;
);
}
- private static getConfiguredNumberOfConnectors(
- stationTemplate: ChargingStationTemplate | ChargingStationInfo
- ): number {
+ private static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
let configuredMaxConnectors: number;
if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {
const numberOfConnectors = stationTemplate.numberOfConnectors as number[];
private static checkConfiguredMaxConnectors(
configuredMaxConnectors: number,
- templateFile: string,
- logPrefix: string
+ logPrefix: string,
+ templateFile: string
): void {
if (configuredMaxConnectors <= 0) {
logger.warn(
private static checkTemplateMaxConnectors(
templateMaxConnectors: number,
- templateFile: string,
- logPrefix: string
+ logPrefix: string,
+ templateFile: string
): void {
if (templateMaxConnectors === 0) {
logger.warn(
private static warnDeprecatedTemplateKey(
template: ChargingStationTemplate,
key: string,
- templateFile: string,
logPrefix: string,
+ templateFile: string,
logMsgToAppend = ''
): void {
if (!Utils.isUndefined(template[key])) {