// Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
+import { randomInt } from 'node:crypto'
+
import { hoursToMilliseconds, secondsToMilliseconds } from 'date-fns'
import { BaseError } from '../exception/index.js'
Constants,
convertToDate,
formatDurationMilliSeconds,
- getRandomInteger,
isValidDate,
logger,
logPrefix,
break
}
const wait = secondsToMilliseconds(
- getRandomInteger(
+ randomInt(
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
- ?.maxDelayBetweenTwoTransactions,
+ ?.minDelayBetweenTwoTransactions,
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
- ?.minDelayBetweenTwoTransactions
+ ?.maxDelayBetweenTwoTransactions
)
)
logger.info(`${this.logPrefix(connectorId)} waiting for ${formatDurationMilliSeconds(wait)}`)
if (startResponse?.idTagInfo.status === AuthorizationStatus.ACCEPTED) {
// Wait until end of transaction
const waitTrxEnd = secondsToMilliseconds(
- getRandomInteger(
- this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.maxDuration,
- this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.minDuration
+ randomInt(
+ this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.minDuration,
+ this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.maxDuration
)
)
logger.info(
const connectorStatus = this.chargingStation.getConnectorStatus(connectorId)
if (connectorStatus?.transactionStarted === true) {
logger.info(
- `${this.logPrefix(
- connectorId
- )} entered in transaction loop while a transaction ${connectorStatus.transactionId} is already started on connector ${connectorId}`
+ `${this.logPrefix(connectorId)} entered in transaction loop while a transaction ${
+ connectorStatus.transactionId
+ } is already started on connector ${connectorId}`
)
return false
}
while (connectorStatus?.transactionStarted === true) {
if (!logged) {
logger.info(
- `${this.logPrefix(
- connectorId
- )} transaction loop waiting for started transaction ${connectorStatus.transactionId} on connector ${connectorId} to be stopped`
+ `${this.logPrefix(connectorId)} transaction loop waiting for started transaction ${
+ connectorStatus.transactionId
+ } on connector ${connectorId} to be stopped`
)
logged = true
}
)
} else if (this.chargingStation.getAutomaticTransactionGeneratorStatuses() != null) {
logger.warn(
- `${this.logPrefix(connectorId)} no status found for connector #${connectorId} in charging station configuration file. New status will be created`
+ `${this.logPrefix(
+ connectorId
+ )} no status found for connector #${connectorId} in charging station configuration file. New status will be created`
)
}
if (connectorStatus != null) {
logger.info(startTransactionLogMsg)
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
- StartTransactionRequest,
+ Partial<StartTransactionRequest>,
StartTransactionResponse
>(this.chargingStation, RequestCommand.START_TRANSACTION, {
connectorId,
logger.info(startTransactionLogMsg)
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
- StartTransactionRequest,
+ Partial<StartTransactionRequest>,
StartTransactionResponse
>(this.chargingStation, RequestCommand.START_TRANSACTION, {
connectorId,
}
logger.info(`${this.logPrefix(connectorId)} start transaction without an idTag`)
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
- StartTransactionRequest,
+ Partial<StartTransactionRequest>,
StartTransactionResponse
- >(this.chargingStation, RequestCommand.START_TRANSACTION, { connectorId })
+ >(this.chargingStation, RequestCommand.START_TRANSACTION, {
+ connectorId
+ })
this.handleStartTransactionResponse(connectorId, startResponse)
PerformanceStatistics.endMeasure(measureId, beginId)
return startResponse