export const getChargingStationId = (
index: number,
- stationTemplate: ChargingStationTemplate
+ stationTemplate: ChargingStationTemplate,
): string => {
// In case of multiple instances: add instance index to charging station id
const instanceIndex = process.env.CF_INSTANCE_INDEX ?? 0;
return stationTemplate?.fixedName
? stationTemplate.baseName
: `${stationTemplate.baseName}-${instanceIndex.toString()}${idStr.substring(
- idStr.length - 4
+ idStr.length - 4,
)}${idSuffix}`;
};
export const checkChargingStation = (
chargingStation: ChargingStation,
- logPrefix: string
+ logPrefix: string,
): boolean => {
if (chargingStation.started === false && chargingStation.starting === false) {
logger.warn(`${logPrefix} charging station is stopped, cannot proceed`);
export const getPhaseRotationValue = (
connectorId: number,
- numberOfPhases: number
+ numberOfPhases: number,
): string | undefined => {
// AC/DC
if (connectorId === 0 && numberOfPhases === 0) {
export const getBootConnectorStatus = (
chargingStation: ChargingStation,
connectorId: number,
- connectorStatus: ConnectorStatus
+ connectorStatus: ConnectorStatus,
): ConnectorStatusEnum => {
let connectorBootStatus: ConnectorStatusEnum;
if (
export const checkTemplate = (
stationTemplate: ChargingStationTemplate,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): void => {
if (isNullOrUndefined(stationTemplate)) {
const errorMsg = `Failed to read charging station template file ${templateFile}`;
stationTemplate.AutomaticTransactionGenerator = Constants.DEFAULT_ATG_CONFIGURATION;
logger.warn(
`${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default: %j`,
- Constants.DEFAULT_ATG_CONFIGURATION
+ Constants.DEFAULT_ATG_CONFIGURATION,
);
}
if (isNullOrUndefined(stationTemplate.idTagsFile) || isEmptyString(stationTemplate.idTagsFile)) {
logger.warn(
- `${logPrefix} Missing id tags file in template file ${templateFile}. That can lead to issues with the Automatic Transaction Generator`
+ `${logPrefix} Missing id tags file in template file ${templateFile}. That can lead to issues with the Automatic Transaction Generator`,
);
}
};
export const checkConnectorsConfiguration = (
stationTemplate: ChargingStationTemplate,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): {
configuredMaxConnectors: number;
templateMaxConnectors: number;
!stationTemplate?.randomConnectors
) {
logger.warn(
- `${logPrefix} Number of connectors exceeds the number of connector configurations in template ${templateFile}, forcing random connector configurations affectation`
+ `${logPrefix} Number of connectors exceeds the number of connector configurations in template ${templateFile}, forcing random connector configurations affectation`,
);
stationTemplate.randomConnectors = true;
}
connectorId: number,
connectorStatus: ConnectorStatus,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): void => {
if (!isNullOrUndefined(connectorStatus?.status)) {
logger.warn(
- `${logPrefix} Charging station information from template ${templateFile} with connector id ${connectorId} status configuration defined, undefine it`
+ `${logPrefix} Charging station information from template ${templateFile} with connector id ${connectorId} status configuration defined, undefine it`,
);
delete connectorStatus.status;
}
export const buildConnectorsMap = (
connectors: Record<string, ConnectorStatus>,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): Map<number, ConnectorStatus> => {
const connectorsMap = new Map<number, ConnectorStatus>();
if (getMaxNumberOfConnectors(connectors) > 0) {
}
} else {
logger.warn(
- `${logPrefix} Charging station information from template ${templateFile} with no connectors, cannot build connectors map`
+ `${logPrefix} Charging station information from template ${templateFile} with no connectors, cannot build connectors map`,
);
}
return connectorsMap;
export const initializeConnectorsMapStatus = (
connectors: Map<number, ConnectorStatus>,
- logPrefix: string
+ logPrefix: string,
): void => {
for (const connectorId of connectors.keys()) {
if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) {
logger.warn(
- `${logPrefix} Connector id ${connectorId} at initialization has a transaction started with id ${
- connectors.get(connectorId)?.transactionId
- }`
+ `${logPrefix} Connector id ${connectorId} at initialization has a transaction started with id ${connectors.get(
+ connectorId,
+ )?.transactionId}`,
);
}
if (connectorId === 0) {
export const createBootNotificationRequest = (
stationInfo: ChargingStationInfo,
- bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp
+ bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp,
): BootNotificationRequest => {
const ocppVersion = stationInfo.ocppVersion ?? OCPPVersion.VERSION_16;
switch (ocppVersion) {
export const warnTemplateKeysDeprecation = (
stationTemplate: ChargingStationTemplate,
logPrefix: string,
- templateFile: string
+ templateFile: string,
) => {
const templateKeys: { key: string; deprecatedKey: string }[] = [
{ key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
templateKey.deprecatedKey,
logPrefix,
templateFile,
- `Use '${templateKey.key}' instead`
+ `Use '${templateKey.key}' instead`,
);
convertDeprecatedTemplateKey(stationTemplate, templateKey.deprecatedKey, templateKey.key);
}
};
export const stationTemplateToStationInfo = (
- stationTemplate: ChargingStationTemplate
+ stationTemplate: ChargingStationTemplate,
): ChargingStationInfo => {
stationTemplate = cloneObject<ChargingStationTemplate>(stationTemplate);
delete stationTemplate.power;
} = {
randomSerialNumberUpperCase: true,
randomSerialNumber: true,
- }
+ },
): void => {
params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params };
const serialNumberSuffix = params?.randomSerialNumber
export const propagateSerialNumber = (
stationTemplate: ChargingStationTemplate,
stationInfoSrc: ChargingStationInfo,
- stationInfoDst: ChargingStationInfo
+ stationInfoDst: ChargingStationInfo,
) => {
if (!stationInfoSrc || !stationTemplate) {
throw new BaseError(
- 'Missing charging station template or existing configuration to propagate serial number'
+ 'Missing charging station template or existing configuration to propagate serial number',
);
}
stationTemplate?.chargePointSerialNumberPrefix && stationInfoSrc?.chargePointSerialNumber
export const getChargingStationConnectorChargingProfilesPowerLimit = (
chargingStation: ChargingStation,
- connectorId: number
+ connectorId: number,
): number | undefined => {
let limit: number, matchingChargingProfile: ChargingProfile;
// Get charging profiles for connector and sort by stack level
const chargingProfiles =
cloneObject<ChargingProfile[]>(
- chargingStation.getConnectorStatus(connectorId)?.chargingProfiles
+ chargingStation.getConnectorStatus(connectorId)?.chargingProfiles,
)?.sort((a, b) => b.stackLevel - a.stackLevel) ?? [];
// Get profiles on connector 0
if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
chargingProfiles.push(
...cloneObject<ChargingProfile[]>(
- chargingStation.getConnectorStatus(0).chargingProfiles
- ).sort((a, b) => b.stackLevel - a.stackLevel)
+ chargingStation.getConnectorStatus(0).chargingProfiles,
+ ).sort((a, b) => b.stackLevel - a.stackLevel),
);
}
if (isNotEmptyArray(chargingProfiles)) {
: ACElectricUtils.powerTotal(
chargingStation.getNumberOfPhases(),
chargingStation.getVoltageOut(),
- limit
+ limit,
);
break;
case CurrentType.DC:
`${chargingStation.logPrefix()} Charging profile id ${
matchingChargingProfile.chargingProfileId
} limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
- result
+ result,
);
limit = connectorMaximumPower;
}
export const getDefaultVoltageOut = (
currentType: CurrentType,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): Voltage => {
const errorMsg = `Unknown ${currentType} currentOutType in template file ${templateFile}, cannot define default voltage out`;
let defaultVoltageOut: number;
export const waitChargingStationEvents = async (
emitter: EventEmitter,
event: ChargingStationWorkerMessageEvents,
- eventsToWait: number
+ eventsToWait: number,
): Promise<number> => {
return new Promise((resolve) => {
let events = 0;
const checkConfiguredMaxConnectors = (
configuredMaxConnectors: number,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): void => {
if (configuredMaxConnectors <= 0) {
logger.warn(
- `${logPrefix} Charging station information from template ${templateFile} with ${configuredMaxConnectors} connectors`
+ `${logPrefix} Charging station information from template ${templateFile} with ${configuredMaxConnectors} connectors`,
);
}
};
const checkTemplateMaxConnectors = (
templateMaxConnectors: number,
logPrefix: string,
- templateFile: string
+ templateFile: string,
): void => {
if (templateMaxConnectors === 0) {
logger.warn(
- `${logPrefix} Charging station information from template ${templateFile} with empty connectors configuration`
+ `${logPrefix} Charging station information from template ${templateFile} with empty connectors configuration`,
);
} else if (templateMaxConnectors < 0) {
logger.error(
- `${logPrefix} Charging station information from template ${templateFile} with no connectors configuration defined`
+ `${logPrefix} Charging station information from template ${templateFile} with no connectors configuration defined`,
);
}
};
key: string,
logPrefix: string,
templateFile: string,
- logMsgToAppend = ''
+ logMsgToAppend = '',
): void => {
if (!isUndefined(template[key])) {
const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
const convertDeprecatedTemplateKey = (
template: ChargingStationTemplate,
deprecatedKey: string,
- key: string
+ key: string,
): void => {
if (!isUndefined(template[deprecatedKey])) {
template[key] = template[deprecatedKey] as unknown;
*/
const getLimitFromChargingProfiles = (
chargingProfiles: ChargingProfile[],
- logPrefix: string
+ logPrefix: string,
): {
limit: number;
matchingChargingProfile: ChargingProfile;
const chargingSchedule = chargingProfile.chargingSchedule;
if (!chargingSchedule?.startSchedule) {
logger.warn(
- `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not defined in charging profile id ${chargingProfile.chargingProfileId}`
+ `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not defined in charging profile id ${chargingProfile.chargingProfileId}`,
);
}
// Check type (recurring) and if it is already active
) {
if (!(chargingSchedule?.startSchedule instanceof Date)) {
logger.warn(
- `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not a Date object in charging profile id ${chargingProfile.chargingProfileId}. Trying to convert it to a Date object`
+ `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not a Date object in charging profile id ${chargingProfile.chargingProfileId}. Trying to convert it to a Date object`,
);
chargingSchedule.startSchedule = new Date(chargingSchedule.startSchedule);
}
chargingSchedule.startSchedule.setFullYear(
currentDate.getFullYear(),
currentDate.getMonth(),
- currentDate.getDate()
+ currentDate.getDate(),
);
// Check if the start of the schedule is yesterday
if (moment(chargingSchedule.startSchedule).isAfter(currentMoment)) {