import { AsyncResource } from 'node:async_hooks';
import type { ChargingStation } from './ChargingStation';
import { AsyncResource } from 'node:async_hooks';
import type { ChargingStation } from './ChargingStation';
import { IdTagsCache } from './IdTagsCache';
import { BaseError } from '../exception';
import { PerformanceStatistics } from '../performance';
import { IdTagsCache } from './IdTagsCache';
import { BaseError } from '../exception';
import { PerformanceStatistics } from '../performance';
): AutomaticTransactionGenerator | undefined {
if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) {
AutomaticTransactionGenerator.instances.set(
chargingStation.stationInfo.hashId,
): AutomaticTransactionGenerator | undefined {
if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) {
AutomaticTransactionGenerator.instances.set(
chargingStation.stationInfo.hashId,
this.runInAsyncScope(
this.internalStartConnector.bind(this) as (
this: AutomaticTransactionGenerator,
this.runInAsyncScope(
this.internalStartConnector.bind(this) as (
this: AutomaticTransactionGenerator,
).catch(Constants.EMPTY_FUNCTION);
} else if (this.connectorsStatus.get(connectorId)?.start === true) {
logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
).catch(Constants.EMPTY_FUNCTION);
} else if (this.connectorsStatus.get(connectorId)?.start === true) {
logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
throw new BaseError(`Connector ${connectorId} does not exist`);
}
if (this.connectorsStatus.get(connectorId)?.start === true) {
throw new BaseError(`Connector ${connectorId} does not exist`);
}
if (this.connectorsStatus.get(connectorId)?.start === true) {
} else if (this.connectorsStatus.get(connectorId)?.start === false) {
logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`);
}
} else if (this.connectorsStatus.get(connectorId)?.start === false) {
logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`);
}
- connectorId
- )} started on connector and will run for ${Utils.formatDurationMilliSeconds(
- this.connectorsStatus.get(connectorId).stopDate.getTime() -
- this.connectorsStatus.get(connectorId).startDate.getTime()
- )}`
+ connectorId,
+ )} started on connector and will run for ${formatDurationMilliSeconds(
+ this.connectorsStatus.get(connectorId)!.stopDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
+ )}`,
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
.maxDelayBetweenTwoTransactions,
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
.maxDelayBetweenTwoTransactions,
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
- logger.info(
- `${this.logPrefix(connectorId)} waiting for ${Utils.formatDurationMilliSeconds(wait)}`
- );
- await Utils.sleep(wait);
- const start = Utils.secureRandom();
+ logger.info(`${this.logPrefix(connectorId)} waiting for ${formatDurationMilliSeconds(wait)}`);
+ await sleep(wait);
+ const start = secureRandom();
// Start transaction
const startResponse = await this.startTransaction(connectorId);
if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
// Wait until end of transaction
const waitTrxEnd =
// Start transaction
const startResponse = await this.startTransaction(connectorId);
if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
// Wait until end of transaction
const waitTrxEnd =
) * 1000;
logger.info(
`${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation
.getConnectorStatus(connectorId)
) * 1000;
logger.info(
`${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation
.getConnectorStatus(connectorId)
// Stop transaction
logger.info(
`${this.logPrefix(connectorId)} stop transaction with id ${this.chargingStation
.getConnectorStatus(connectorId)
// Stop transaction
logger.info(
`${this.logPrefix(connectorId)} stop transaction with id ${this.chargingStation
.getConnectorStatus(connectorId)
- ++this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions;
- ++this.connectorsStatus.get(connectorId).skippedTransactions;
+ ++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)
logger.info(
`${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus
.get(connectorId)
?.skippedConsecutiveTransactions?.toString()}/${this.connectorsStatus
.get(connectorId)
- connectorId
- )} stopped on connector and lasted for ${Utils.formatDurationMilliSeconds(
- this.connectorsStatus.get(connectorId).stoppedDate.getTime() -
- this.connectorsStatus.get(connectorId).startDate.getTime()
- )}`
+ connectorId,
+ )} stopped on connector and lasted for ${formatDurationMilliSeconds(
+ this.connectorsStatus.get(connectorId)!.stoppedDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
+ )}`,
const previousRunDuration =
this.connectorsStatus.get(connectorId)?.startDate &&
this.connectorsStatus.get(connectorId)?.lastRunDate
const previousRunDuration =
this.connectorsStatus.get(connectorId)?.startDate &&
this.connectorsStatus.get(connectorId)?.lastRunDate
- ? this.connectorsStatus.get(connectorId).lastRunDate.getTime() -
- this.connectorsStatus.get(connectorId).startDate.getTime()
+ ? this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime()
- this.connectorsStatus.get(connectorId).startDate = new Date();
- this.connectorsStatus.get(connectorId).stopDate = new Date(
- this.connectorsStatus.get(connectorId).startDate.getTime() +
+ this.connectorsStatus.get(connectorId)!.startDate = new Date();
+ this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
- const connectorStatus = Utils.cloneObject(
- this.chargingStation.getAutomaticTransactionGeneratorStatuses()
- )[connectorId];
+ const connectorStatus = this.chargingStation.getAutomaticTransactionGeneratorStatuses()
+ ? cloneObject(this.chargingStation.getAutomaticTransactionGeneratorStatuses()!)[connectorId]
+ : undefined;
delete connectorStatus?.startDate;
delete connectorStatus?.lastRunDate;
delete connectorStatus?.stopDate;
delete connectorStatus?.startDate;
delete connectorStatus?.lastRunDate;
delete connectorStatus?.stopDate;
): Promise<StartTransactionResponse | undefined> {
const measureId = 'StartTransaction with ATG';
const beginId = PerformanceStatistics.beginMeasure(measureId);
): Promise<StartTransactionResponse | undefined> {
const measureId = 'StartTransaction with ATG';
const beginId = PerformanceStatistics.beginMeasure(measureId);
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
await this.chargingStation.ocppRequestService.requestHandler<
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
await this.chargingStation.ocppRequestService.requestHandler<
logger.info(startTransactionLogMsg);
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
logger.info(startTransactionLogMsg);
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
- reason: StopTransactionReason = StopTransactionReason.LOCAL
- ): Promise<StopTransactionResponse> {
+ reason: StopTransactionReason = StopTransactionReason.LOCAL,
+ ): Promise<StopTransactionResponse | undefined> {
const measureId = 'StopTransaction with ATG';
const beginId = PerformanceStatistics.beginMeasure(measureId);
const measureId = 'StopTransaction with ATG';
const beginId = PerformanceStatistics.beginMeasure(measureId);
if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason);
if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason);
}
} else {
const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
logger.warn(
`${this.logPrefix(connectorId)} stopping a not started transaction${
}
} else {
const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
logger.warn(
`${this.logPrefix(connectorId)} stopping a not started transaction${