if (this.chargingStation.getEnableStatistics()) {
this.performanceObserver = new PerformanceObserver((list) => {
const entry = list.getEntries()[0];
- this.chargingStation.statistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR);
+ this.chargingStation.performanceStatistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR);
this.performanceObserver.disconnect();
});
}
}
- public start(): void {
+ public async start(): Promise<void> {
this.timeToStop = false;
if (this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours &&
this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours > 0) {
- setTimeout(() => {
- void this.stop();
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
+ setTimeout(async (): Promise<void> => {
+ await this.stop();
}, this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000);
}
for (const connector in this.chargingStation.connectors) {
if (Utils.convertToInt(connector) > 0) {
- void this.startConnector(Utils.convertToInt(connector));
+ await this.startConnector(Utils.convertToInt(connector));
}
}
logger.info(this.logPrefix() + ' ATG started and will stop in ' + Utils.secondsToHHMMSS(this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600));
const transactionId = this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionId;
if (this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionStarted) {
logger.info(this.logPrefix(Utils.convertToInt(connector)) + ' ATG OVER. Stop transaction ' + transactionId.toString());
- await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getTransactionMeterStop(transactionId), this.chargingStation.getTransactionIdTag(transactionId), reason);
+ await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getTransactionMeterStop(transactionId),
+ this.chargingStation.getTransactionIdTag(transactionId), reason);
}
}
this.timeToStop = true;
}
- public async startConnector(connectorId: number): Promise<void> {
+ private async startConnector(connectorId: number): Promise<void> {
do {
if (this.timeToStop) {
logger.error(this.logPrefix(connectorId) + ' Entered in transaction loop while a request to stop it was made');
if (!this.chargingStation?.ocppRequestService) {
logger.info(`${this.logPrefix(connectorId)} Transaction loop waiting for charging station service to be initialized`);
do {
- await Utils.sleep(500);
+ await Utils.sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
} while (!this.chargingStation?.ocppRequestService);
}
const wait = Utils.getRandomInt(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransactions,
startResponse = await this.startTransaction(connectorId, this);
}
if (startResponse?.idTagInfo?.status !== AuthorizationStatus.ACCEPTED) {
- logger.info(this.logPrefix(connectorId) + ' transaction rejected');
+ logger.warn(this.logPrefix(connectorId) + ' transaction rejected');
await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME);
} else {
// Wait until end of transaction
private logPrefix(connectorId: number = null): string {
if (connectorId) {
- return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG on connector #' + connectorId.toString() + ':');
+ return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' | ATG on connector #' + connectorId.toString() + ':');
}
- return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG:');
+ return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' | ATG:');
}
}