),
);
logger.info(
- `${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation
- .getConnectorStatus(connectorId)
- ?.transactionId?.toString()} and will stop in ${formatDurationMilliSeconds(
- waitTrxEnd,
- )}`,
+ `${this.logPrefix(
+ connectorId,
+ )} transaction started with id ${this.chargingStation.getConnectorStatus(connectorId)
+ ?.transactionId} and will stop in ${formatDurationMilliSeconds(waitTrxEnd)}`,
);
await sleep(waitTrxEnd);
// Stop transaction
logger.info(
- `${this.logPrefix(connectorId)} stop transaction with id ${this.chargingStation
- .getConnectorStatus(connectorId)
- ?.transactionId?.toString()}`,
+ `${this.logPrefix(
+ connectorId,
+ )} stop transaction with id ${this.chargingStation.getConnectorStatus(connectorId)
+ ?.transactionId}`,
);
await this.stopTransaction(connectorId);
}
++this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions!;
++this.connectorsStatus.get(connectorId)!.skippedTransactions!;
logger.info(
- `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus
- .get(connectorId)
- ?.skippedConsecutiveTransactions?.toString()}/${this.connectorsStatus
- .get(connectorId)
- ?.skippedTransactions?.toString()} transaction(s)`,
+ `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus.get(
+ connectorId,
+ )?.skippedConsecutiveTransactions}/${this.connectorsStatus.get(connectorId)
+ ?.skippedTransactions} transaction(s)`,
);
}
this.connectorsStatus.get(connectorId)!.lastRunDate = new Date();
const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
logger.warn(
`${this.logPrefix(connectorId)} stopping a not started transaction${
- !isNullOrUndefined(transactionId) ? ` with id ${transactionId?.toString()}` : ''
+ !isNullOrUndefined(transactionId) ? ` with id ${transactionId}` : ''
}`,
);
}
private logPrefix = (connectorId?: number): string => {
return logPrefix(
` ${this.chargingStation.stationInfo.chargingStationId} | ATG${
- !isNullOrUndefined(connectorId) ? ` on connector #${connectorId!.toString()}` : ''
+ !isNullOrUndefined(connectorId) ? ` on connector #${connectorId}` : ''
}:`,
);
};
public getMaximumPower(stationInfo?: ChargingStationInfo): number {
const localStationInfo = stationInfo ?? this.stationInfo;
return (
- (localStationInfo['maxPower' as keyof ChargingStationInfo] as number) ??
+ (localStationInfo?.['maxPower' as keyof ChargingStationInfo] as number) ??
localStationInfo.maximumPower
);
}
for (let connectorId = 0; connectorId <= configuredMaxConnectors; connectorId++) {
if (
connectorId === 0 &&
- (!stationTemplate?.Connectors[connectorId] ||
+ (!stationTemplate?.Connectors?.[connectorId] ||
this.getUseConnectorId0(stationTemplate) === false)
) {
continue;
checkConfiguredMaxConnectors(configuredMaxConnectors, logPrefix, templateFile);
const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors!);
checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile);
- const templateMaxAvailableConnectors = stationTemplate.Connectors![0]
+ const templateMaxAvailableConnectors = stationTemplate.Connectors?.[0]
? templateMaxConnectors - 1
: templateMaxConnectors;
if (
} else if (isUndefined(stationTemplate.numberOfConnectors) === false) {
configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number;
} else if (stationTemplate.Connectors && !stationTemplate.Evses) {
- configuredMaxNumberOfConnectors = stationTemplate.Connectors[0]
+ configuredMaxNumberOfConnectors = stationTemplate.Connectors?.[0]
? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1
: getMaxNumberOfConnectors(stationTemplate.Connectors);
} else if (stationTemplate.Evses && !stationTemplate.Connectors) {
templateFile: string,
logMsgToAppend = '',
): void => {
- if (!isUndefined(template[key as keyof ChargingStationTemplate])) {
+ if (!isUndefined(template?.[key as keyof ChargingStationTemplate])) {
const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`;
deprecatedKey: string,
key?: string,
): void => {
- if (!isUndefined(template[deprecatedKey as keyof ChargingStationTemplate])) {
+ if (!isUndefined(template?.[deprecatedKey as keyof ChargingStationTemplate])) {
if (!isUndefined(key)) {
(template as unknown as Record<string, unknown>)[key!] =
template[deprecatedKey as keyof ChargingStationTemplate];
return true;
} else if (
isRequestCommand === true &&
- chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+ chargingStation.stationInfo?.commandsSupport?.outgoingCommands?.[command]
) {
- return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
+ return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command];
}
logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
return false;
return true;
} else if (
isIncomingRequestCommand === true &&
- chargingStation.stationInfo?.commandsSupport?.incomingCommands
+ chargingStation.stationInfo?.commandsSupport?.incomingCommands?.[command]
) {
- return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;
+ return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command];
}
logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`);
return false;
const isMessageTrigger = Object.values(MessageTrigger).includes(messageTrigger);
if (isMessageTrigger === true && !chargingStation.stationInfo?.messageTriggerSupport) {
return true;
- } else if (isMessageTrigger === true && chargingStation.stationInfo?.messageTriggerSupport) {
- return chargingStation.stationInfo?.messageTriggerSupport[messageTrigger] ?? false;
+ } else if (
+ isMessageTrigger === true &&
+ chargingStation.stationInfo?.messageTriggerSupport?.[messageTrigger]
+ ) {
+ return chargingStation.stationInfo?.messageTriggerSupport[messageTrigger];
}
logger.error(
`${chargingStation.logPrefix()} Unknown incoming OCPP message trigger '${messageTrigger}'`,
return sampledValueTemplates[index];
} else if (
!phase &&
- !sampledValueTemplates[index].phase &&
+ !sampledValueTemplates[index]?.phase &&
sampledValueTemplates[index]?.measurand === measurand &&
getConfigurationKey(
chargingStation,
return sampledValueTemplates[index];
} else if (
measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- (!sampledValueTemplates[index].measurand ||
- sampledValueTemplates[index].measurand === measurand)
+ (!sampledValueTemplates[index]?.measurand ||
+ sampledValueTemplates[index]?.measurand === measurand)
) {
return sampledValueTemplates[index];
}
}
public sendResponse(response: ProtocolResponse): void {
- const responseId = response[0];
+ const responseId = response?.[0];
try {
if (this.hasResponseHandler(responseId)) {
const ws = this.responseHandlers.get(responseId) as WebSocket;
return false;
}
- if (validateUUID(request[0]) === false) {
+ if (validateUUID(request?.[0]) === false) {
logger.error(
`${this.logPrefix(
moduleName,
}
public static getAutoReconnectMaxRetries(): number | undefined {
- if (hasOwnProp(Configuration.getConfigurationData(), 'autoReconnectMaxRetries')) {
- return Configuration.getConfigurationData()?.autoReconnectMaxRetries;
- }
+ return Configuration.getConfigurationData()?.autoReconnectMaxRetries;
}
public static getStationTemplateUrls(): StationTemplateUrl[] | undefined {
public static getSupervisionUrls(): string | string[] | undefined {
if (
!isUndefined(
- Configuration.getConfigurationData()!['supervisionURLs' as keyof ConfigurationData],
+ Configuration.getConfigurationData()?.['supervisionURLs' as keyof ConfigurationData],
)
) {
Configuration.getConfigurationData()!.supervisionUrls = Configuration.getConfigurationData()![
"Use 'stationTemplateUrls' instead",
);
!isUndefined(
- Configuration.getConfigurationData()!['stationTemplateURLs' as keyof ConfigurationData],
+ Configuration.getConfigurationData()?.['stationTemplateURLs' as keyof ConfigurationData],
) &&
(Configuration.getConfigurationData()!.stationTemplateUrls =
Configuration.getConfigurationData()![
'stationTemplateURLs' as keyof ConfigurationData
] as StationTemplateUrl[]);
- Configuration.getConfigurationData()!.stationTemplateUrls.forEach(
+ Configuration.getConfigurationData()?.stationTemplateUrls.forEach(
(stationTemplateUrl: StationTemplateUrl) => {
- if (!isUndefined(stationTemplateUrl['numberOfStation' as keyof StationTemplateUrl])) {
+ if (!isUndefined(stationTemplateUrl?.['numberOfStation' as keyof StationTemplateUrl])) {
console.error(
`${chalk.green(Configuration.logPrefix())} ${chalk.red(
`Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`,
) {
if (
sectionName &&
- !isUndefined(Configuration.getConfigurationData()![sectionName as keyof ConfigurationData]) &&
+ !isUndefined(
+ Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData],
+ ) &&
!isUndefined(
(
- Configuration.getConfigurationData()![sectionName as keyof ConfigurationData] as Record<
+ Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record<
string,
unknown
>
- )[key],
+ )?.[key],
)
) {
console.error(
)}`,
);
} else if (
- !isUndefined(Configuration.getConfigurationData()![key as keyof ConfigurationData])
+ !isUndefined(Configuration.getConfigurationData()?.[key as keyof ConfigurationData])
) {
console.error(
`${chalk.green(Configuration.logPrefix())} ${chalk.red(