fix: avoid NaN at meterValues generation
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
CommitLineData
edd13439 1// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
c8eeb62b 2
01f4001e 3import { AsyncResource } from 'node:async_hooks';
d4b944ae 4
be4c6702
JB
5import { hoursToMilliseconds, secondsToMilliseconds } from 'date-fns';
6
4c3c0d59 7import type { ChargingStation } from './ChargingStation';
08b58f00 8import { checkChargingStation } from './Helpers';
4c3c0d59 9import { IdTagsCache } from './IdTagsCache';
ae725be3 10import { OCPPServiceUtils } from './ocpp';
268a74bb 11import { BaseError } from '../exception';
b84bca85 12import { PerformanceStatistics } from '../performance';
e7aeea18
JB
13import {
14 AuthorizationStatus,
9b4d0c70 15 ConnectorStatusEnum,
268a74bb 16 RequestCommand,
976d11ec
JB
17 type StartTransactionRequest,
18 type StartTransactionResponse,
268a74bb 19 type Status,
e7aeea18 20 StopTransactionReason,
976d11ec 21 type StopTransactionResponse,
268a74bb 22} from '../types';
9bf0ef23
JB
23import {
24 Constants,
25 cloneObject,
26 formatDurationMilliSeconds,
27 getRandomInteger,
28 isNullOrUndefined,
29 logPrefix,
30 logger,
31 secureRandom,
32 sleep,
33} from '../utils';
6af9012e 34
d4b944ae
JB
35const moduleName = 'AutomaticTransactionGenerator';
36
268a74bb 37export class AutomaticTransactionGenerator extends AsyncResource {
e7aeea18
JB
38 private static readonly instances: Map<string, AutomaticTransactionGenerator> = new Map<
39 string,
40 AutomaticTransactionGenerator
41 >();
10068088 42
5e3cb728 43 public readonly connectorsStatus: Map<number, Status>;
265e4266 44 public started: boolean;
11353865
JB
45 private starting: boolean;
46 private stopping: boolean;
9e23580d 47 private readonly chargingStation: ChargingStation;
6af9012e 48
ac7f79af 49 private constructor(chargingStation: ChargingStation) {
d4b944ae 50 super(moduleName);
aa428a31 51 this.started = false;
11353865
JB
52 this.starting = false;
53 this.stopping = false;
ad2f27c3 54 this.chargingStation = chargingStation;
7807ccf2
JB
55 this.connectorsStatus = new Map<number, Status>();
56 this.initializeConnectorsStatus();
6af9012e
JB
57 }
58
fa7bccf4 59 public static getInstance(
5edd8ba0 60 chargingStation: ChargingStation,
1895299d 61 ): AutomaticTransactionGenerator | undefined {
4dff3039 62 if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) {
e7aeea18 63 AutomaticTransactionGenerator.instances.set(
51c83d6f 64 chargingStation.stationInfo.hashId,
5edd8ba0 65 new AutomaticTransactionGenerator(chargingStation),
e7aeea18 66 );
73b9adec 67 }
51c83d6f 68 return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo.hashId);
73b9adec
JB
69 }
70
7d75bee1 71 public start(): void {
fba11dc6 72 if (checkChargingStation(this.chargingStation, this.logPrefix()) === false) {
d1c6c833
JB
73 return;
74 }
a5e9befc 75 if (this.started === true) {
ba7965c4 76 logger.warn(`${this.logPrefix()} is already started`);
b809adf1
JB
77 return;
78 }
11353865
JB
79 if (this.starting === true) {
80 logger.warn(`${this.logPrefix()} is already starting`);
81 return;
82 }
83 this.starting = true;
72740232 84 this.startConnectors();
265e4266 85 this.started = true;
11353865 86 this.starting = false;
6af9012e
JB
87 }
88
9ff486f4 89 public stop(): void {
a5e9befc 90 if (this.started === false) {
ba7965c4 91 logger.warn(`${this.logPrefix()} is already stopped`);
265e4266
JB
92 return;
93 }
11353865
JB
94 if (this.stopping === true) {
95 logger.warn(`${this.logPrefix()} is already stopping`);
96 return;
97 }
98 this.stopping = true;
9ff486f4 99 this.stopConnectors();
265e4266 100 this.started = false;
11353865 101 this.stopping = false;
6af9012e
JB
102 }
103
a5e9befc 104 public startConnector(connectorId: number): void {
fba11dc6 105 if (checkChargingStation(this.chargingStation, this.logPrefix(connectorId)) === false) {
d1c6c833
JB
106 return;
107 }
7807ccf2 108 if (this.connectorsStatus.has(connectorId) === false) {
a03a128d 109 logger.error(`${this.logPrefix(connectorId)} starting on non existing connector`);
7807ccf2 110 throw new BaseError(`Connector ${connectorId} does not exist`);
a5e9befc
JB
111 }
112 if (this.connectorsStatus.get(connectorId)?.start === false) {
d4b944ae 113 this.runInAsyncScope(
e6159ce8
JB
114 this.internalStartConnector.bind(this) as (
115 this: AutomaticTransactionGenerator,
e843aa40 116 ...args: unknown[]
64818750 117 ) => Promise<void>,
d4b944ae 118 this,
5edd8ba0 119 connectorId,
59b6ed8d 120 ).catch(Constants.EMPTY_FUNCTION);
ecb3869d 121 } else if (this.connectorsStatus.get(connectorId)?.start === true) {
ba7965c4 122 logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
a5e9befc
JB
123 }
124 }
125
9ff486f4 126 public stopConnector(connectorId: number): void {
7807ccf2 127 if (this.connectorsStatus.has(connectorId) === false) {
a03a128d 128 logger.error(`${this.logPrefix(connectorId)} stopping on non existing connector`);
7807ccf2 129 throw new BaseError(`Connector ${connectorId} does not exist`);
ba7965c4
JB
130 }
131 if (this.connectorsStatus.get(connectorId)?.start === true) {
e1d9a0f4 132 this.connectorsStatus.get(connectorId)!.start = false;
ba7965c4
JB
133 } else if (this.connectorsStatus.get(connectorId)?.start === false) {
134 logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`);
135 }
a5e9befc
JB
136 }
137
72740232 138 private startConnectors(): void {
e7aeea18
JB
139 if (
140 this.connectorsStatus?.size > 0 &&
141 this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()
142 ) {
54544ef1 143 this.connectorsStatus.clear();
7807ccf2 144 this.initializeConnectorsStatus();
54544ef1 145 }
4334db72
JB
146 if (this.chargingStation.hasEvses) {
147 for (const [evseId, evseStatus] of this.chargingStation.evses) {
148 if (evseId > 0) {
149 for (const connectorId of evseStatus.connectors.keys()) {
150 this.startConnector(connectorId);
151 }
152 }
153 }
154 } else {
155 for (const connectorId of this.chargingStation.connectors.keys()) {
156 if (connectorId > 0) {
157 this.startConnector(connectorId);
158 }
72740232
JB
159 }
160 }
161 }
162
9ff486f4 163 private stopConnectors(): void {
4334db72
JB
164 if (this.chargingStation.hasEvses) {
165 for (const [evseId, evseStatus] of this.chargingStation.evses) {
166 if (evseId > 0) {
167 for (const connectorId of evseStatus.connectors.keys()) {
9ff486f4 168 this.stopConnector(connectorId);
4334db72
JB
169 }
170 }
171 }
172 } else {
173 for (const connectorId of this.chargingStation.connectors.keys()) {
174 if (connectorId > 0) {
9ff486f4 175 this.stopConnector(connectorId);
4334db72 176 }
72740232
JB
177 }
178 }
179 }
180
83a3286a 181 private async internalStartConnector(connectorId: number): Promise<void> {
083fb002 182 this.setStartConnectorStatus(connectorId);
e7aeea18 183 logger.info(
44eb6026 184 `${this.logPrefix(
5edd8ba0 185 connectorId,
9bf0ef23 186 )} started on connector and will run for ${formatDurationMilliSeconds(
e1d9a0f4
JB
187 this.connectorsStatus.get(connectorId)!.stopDate!.getTime() -
188 this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
5edd8ba0 189 )}`,
e7aeea18 190 );
1895299d 191 while (this.connectorsStatus.get(connectorId)?.start === true) {
3e888c65
JB
192 await this.waitChargingStationServiceInitialization(connectorId);
193 await this.waitChargingStationAvailable(connectorId);
194 await this.waitConnectorAvailable(connectorId);
0bd926c1 195 if (!this.canStartConnector(connectorId)) {
9ff486f4 196 this.stopConnector(connectorId);
9b4d0c70
JB
197 break;
198 }
be4c6702 199 const wait = secondsToMilliseconds(
9bf0ef23 200 getRandomInteger(
ac7f79af 201 this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
86b46b49 202 .maxDelayBetweenTwoTransactions,
ac7f79af 203 this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
5edd8ba0 204 .minDelayBetweenTwoTransactions,
be4c6702
JB
205 ),
206 );
9bf0ef23
JB
207 logger.info(`${this.logPrefix(connectorId)} waiting for ${formatDurationMilliSeconds(wait)}`);
208 await sleep(wait);
209 const start = secureRandom();
ac7f79af
JB
210 if (
211 start <
212 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().probabilityOfStart
213 ) {
e1d9a0f4 214 this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0;
6af9012e 215 // Start transaction
aef1b33a 216 const startResponse = await this.startTransaction(connectorId);
0afed85f 217 if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
6af9012e 218 // Wait until end of transaction
be4c6702 219 const waitTrxEnd = secondsToMilliseconds(
9bf0ef23 220 getRandomInteger(
86b46b49 221 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration,
5edd8ba0 222 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration,
be4c6702
JB
223 ),
224 );
e7aeea18 225 logger.info(
1c9de2b9
JB
226 `${this.logPrefix(
227 connectorId,
228 )} transaction started with id ${this.chargingStation.getConnectorStatus(connectorId)
229 ?.transactionId} and will stop in ${formatDurationMilliSeconds(waitTrxEnd)}`,
e7aeea18 230 );
9bf0ef23 231 await sleep(waitTrxEnd);
85d20667 232 await this.stopTransaction(connectorId);
6af9012e
JB
233 }
234 } else {
e1d9a0f4
JB
235 ++this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions!;
236 ++this.connectorsStatus.get(connectorId)!.skippedTransactions!;
e7aeea18 237 logger.info(
1c9de2b9
JB
238 `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus.get(
239 connectorId,
240 )?.skippedConsecutiveTransactions}/${this.connectorsStatus.get(connectorId)
241 ?.skippedTransactions} transaction(s)`,
e7aeea18 242 );
6af9012e 243 }
e1d9a0f4 244 this.connectorsStatus.get(connectorId)!.lastRunDate = new Date();
7d75bee1 245 }
e1d9a0f4 246 this.connectorsStatus.get(connectorId)!.stoppedDate = new Date();
e7aeea18 247 logger.info(
44eb6026 248 `${this.logPrefix(
5edd8ba0 249 connectorId,
9bf0ef23 250 )} stopped on connector and lasted for ${formatDurationMilliSeconds(
e1d9a0f4
JB
251 this.connectorsStatus.get(connectorId)!.stoppedDate!.getTime() -
252 this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
5edd8ba0 253 )}`,
e7aeea18
JB
254 );
255 logger.debug(
be9ee554 256 `${this.logPrefix(connectorId)} connector status: %j`,
5edd8ba0 257 this.connectorsStatus.get(connectorId),
e7aeea18 258 );
6af9012e
JB
259 }
260
083fb002 261 private setStartConnectorStatus(connectorId: number): void {
e1d9a0f4 262 this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0;
e7aeea18 263 const previousRunDuration =
72092cfc
JB
264 this.connectorsStatus.get(connectorId)?.startDate &&
265 this.connectorsStatus.get(connectorId)?.lastRunDate
e1d9a0f4
JB
266 ? this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() -
267 this.connectorsStatus.get(connectorId)!.startDate!.getTime()
e7aeea18 268 : 0;
e1d9a0f4
JB
269 this.connectorsStatus.get(connectorId)!.startDate = new Date();
270 this.connectorsStatus.get(connectorId)!.stopDate = new Date(
271 this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
be4c6702
JB
272 hoursToMilliseconds(
273 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours,
274 ) -
5edd8ba0 275 previousRunDuration,
e7aeea18 276 );
e1d9a0f4 277 this.connectorsStatus.get(connectorId)!.start = true;
4dff3039
JB
278 }
279
0bd926c1
JB
280 private canStartConnector(connectorId: number): boolean {
281 if (new Date() > this.connectorsStatus.get(connectorId)!.stopDate!) {
282 return false;
283 }
284 if (this.chargingStation.inAcceptedState() === false) {
285 logger.error(
286 `${this.logPrefix(
287 connectorId,
288 )} entered in transaction loop while the charging station is not in accepted state`,
289 );
290 return false;
291 }
292 if (this.chargingStation.isChargingStationAvailable() === false) {
293 logger.info(
294 `${this.logPrefix(
295 connectorId,
296 )} entered in transaction loop while the charging station is unavailable`,
297 );
298 return false;
299 }
300 if (this.chargingStation.isConnectorAvailable(connectorId) === false) {
301 logger.info(
302 `${this.logPrefix(
303 connectorId,
304 )} entered in transaction loop while the connector ${connectorId} is unavailable`,
305 );
306 return false;
307 }
308 if (
309 this.chargingStation.getConnectorStatus(connectorId)?.status ===
310 ConnectorStatusEnum.Unavailable
311 ) {
312 logger.info(
313 `${this.logPrefix(
314 connectorId,
315 )} entered in transaction loop while the connector ${connectorId} status is unavailable`,
316 );
317 return false;
318 }
319 return true;
320 }
321
3e888c65 322 private async waitChargingStationServiceInitialization(connectorId: number): Promise<void> {
60400e23
JB
323 let logged = false;
324 while (!this.chargingStation?.ocppRequestService) {
325 if (!logged) {
326 logger.info(
327 `${this.logPrefix(
328 connectorId,
329 )} transaction loop waiting for charging station service to be initialized`,
330 );
331 logged = true;
332 }
333 await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
3e888c65
JB
334 }
335 }
336
337 private async waitChargingStationAvailable(connectorId: number): Promise<void> {
60400e23
JB
338 let logged = false;
339 while (!this.chargingStation.isChargingStationAvailable()) {
340 if (!logged) {
341 logger.info(
342 `${this.logPrefix(
343 connectorId,
344 )} transaction loop waiting for charging station to be available`,
345 );
346 logged = true;
347 }
348 await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
3e888c65
JB
349 }
350 }
351
352 private async waitConnectorAvailable(connectorId: number): Promise<void> {
60400e23
JB
353 let logged = false;
354 while (!this.chargingStation.isConnectorAvailable(connectorId)) {
355 if (!logged) {
356 logger.info(
357 `${this.logPrefix(
358 connectorId,
359 )} transaction loop waiting for connector ${connectorId} to be available`,
360 );
361 logged = true;
362 }
363 await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
3e888c65
JB
364 }
365 }
366
7807ccf2 367 private initializeConnectorsStatus(): void {
4334db72
JB
368 if (this.chargingStation.hasEvses) {
369 for (const [evseId, evseStatus] of this.chargingStation.evses) {
370 if (evseId > 0) {
371 for (const connectorId of evseStatus.connectors.keys()) {
5ced7e80 372 this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
4334db72
JB
373 }
374 }
375 }
376 } else {
377 for (const connectorId of this.chargingStation.connectors.keys()) {
378 if (connectorId > 0) {
5ced7e80 379 this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
4334db72 380 }
4dff3039
JB
381 }
382 }
72740232
JB
383 }
384
5ced7e80 385 private getConnectorStatus(connectorId: number): Status {
0a0da58d
JB
386 const connectorStatus = this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[
387 connectorId
388 ]
a82d0329
JB
389 ? cloneObject<Status>(
390 this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId],
391 )
bdc9dc79 392 : undefined;
3d20f4db 393 this.resetConnectorStatus(connectorStatus);
5ced7e80
JB
394 return (
395 connectorStatus ?? {
396 start: false,
397 authorizeRequests: 0,
398 acceptedAuthorizeRequests: 0,
399 rejectedAuthorizeRequests: 0,
400 startTransactionRequests: 0,
401 acceptedStartTransactionRequests: 0,
402 rejectedStartTransactionRequests: 0,
403 stopTransactionRequests: 0,
404 acceptedStopTransactionRequests: 0,
405 rejectedStopTransactionRequests: 0,
406 skippedConsecutiveTransactions: 0,
407 skippedTransactions: 0,
408 }
409 );
410 }
411
3d20f4db
JB
412 private resetConnectorStatus(connectorStatus: Status | undefined): void {
413 delete connectorStatus?.startDate;
414 delete connectorStatus?.lastRunDate;
415 delete connectorStatus?.stopDate;
416 delete connectorStatus?.stoppedDate;
417 if (
418 !this.started &&
419 (connectorStatus?.start === true ||
420 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().enable === false)
421 ) {
422 connectorStatus!.start = false;
423 }
424 }
425
e7aeea18 426 private async startTransaction(
5edd8ba0 427 connectorId: number,
0afed85f 428 ): Promise<StartTransactionResponse | undefined> {
aef1b33a
JB
429 const measureId = 'StartTransaction with ATG';
430 const beginId = PerformanceStatistics.beginMeasure(measureId);
e1d9a0f4 431 let startResponse: StartTransactionResponse | undefined;
f911a4af
JB
432 if (this.chargingStation.hasIdTags()) {
433 const idTag = IdTagsCache.getInstance().getIdTag(
e1d9a0f4 434 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().idTagDistribution!,
aaf2bf9c 435 this.chargingStation,
5edd8ba0 436 connectorId,
aaf2bf9c 437 );
5cf9050d 438 const startTransactionLogMsg = `${this.logPrefix(
5edd8ba0 439 connectorId,
ba7965c4 440 )} start transaction with an idTag '${idTag}'`;
ccb1d6e9 441 if (this.getRequireAuthorize()) {
e1d9a0f4 442 ++this.connectorsStatus.get(connectorId)!.authorizeRequests!;
ae725be3 443 if (await OCPPServiceUtils.isIdTagAuthorized(this.chargingStation, connectorId, idTag)) {
e1d9a0f4 444 ++this.connectorsStatus.get(connectorId)!.acceptedAuthorizeRequests!;
5cf9050d 445 logger.info(startTransactionLogMsg);
5fdab605 446 // Start transaction
f7f98c68 447 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
448 StartTransactionRequest,
449 StartTransactionResponse
08f130a0 450 >(this.chargingStation, RequestCommand.START_TRANSACTION, {
ef6fa3fb
JB
451 connectorId,
452 idTag,
453 });
d9ac47ef 454 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
455 PerformanceStatistics.endMeasure(measureId, beginId);
456 return startResponse;
5fdab605 457 }
e1d9a0f4 458 ++this.connectorsStatus.get(connectorId)!.rejectedAuthorizeRequests!;
aef1b33a 459 PerformanceStatistics.endMeasure(measureId, beginId);
0afed85f 460 return startResponse;
ef6076c1 461 }
5cf9050d 462 logger.info(startTransactionLogMsg);
5fdab605 463 // Start transaction
f7f98c68 464 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
465 StartTransactionRequest,
466 StartTransactionResponse
08f130a0 467 >(this.chargingStation, RequestCommand.START_TRANSACTION, {
ef6fa3fb
JB
468 connectorId,
469 idTag,
470 });
d9ac47ef 471 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
472 PerformanceStatistics.endMeasure(measureId, beginId);
473 return startResponse;
6af9012e 474 }
5cf9050d 475 logger.info(`${this.logPrefix(connectorId)} start transaction without an idTag`);
f7f98c68 476 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
477 StartTransactionRequest,
478 StartTransactionResponse
08f130a0 479 >(this.chargingStation, RequestCommand.START_TRANSACTION, { connectorId });
431b6bd5 480 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
481 PerformanceStatistics.endMeasure(measureId, beginId);
482 return startResponse;
6af9012e
JB
483 }
484
e7aeea18
JB
485 private async stopTransaction(
486 connectorId: number,
9ff486f4 487 reason = StopTransactionReason.LOCAL,
e1d9a0f4 488 ): Promise<StopTransactionResponse | undefined> {
aef1b33a
JB
489 const measureId = 'StopTransaction with ATG';
490 const beginId = PerformanceStatistics.beginMeasure(measureId);
e1d9a0f4 491 let stopResponse: StopTransactionResponse | undefined;
6d9876e7 492 if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
49563992
JB
493 logger.info(
494 `${this.logPrefix(
495 connectorId,
496 )} stop transaction with id ${this.chargingStation.getConnectorStatus(connectorId)
497 ?.transactionId}`,
498 );
5e3cb728 499 stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason);
e1d9a0f4 500 ++this.connectorsStatus.get(connectorId)!.stopTransactionRequests!;
0afed85f 501 if (stopResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
e1d9a0f4 502 ++this.connectorsStatus.get(connectorId)!.acceptedStopTransactionRequests!;
6d9876e7 503 } else {
e1d9a0f4 504 ++this.connectorsStatus.get(connectorId)!.rejectedStopTransactionRequests!;
6d9876e7 505 }
0045cef5 506 } else {
1895299d 507 const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
ff581359 508 logger.debug(
ba7965c4 509 `${this.logPrefix(connectorId)} stopping a not started transaction${
1c9de2b9 510 !isNullOrUndefined(transactionId) ? ` with id ${transactionId}` : ''
5edd8ba0 511 }`,
e7aeea18 512 );
0045cef5 513 }
aef1b33a
JB
514 PerformanceStatistics.endMeasure(measureId, beginId);
515 return stopResponse;
c0560973
JB
516 }
517
ccb1d6e9 518 private getRequireAuthorize(): boolean {
ac7f79af
JB
519 return (
520 this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.requireAuthorize ?? true
521 );
ccb1d6e9
JB
522 }
523
8b7072dc 524 private logPrefix = (connectorId?: number): string => {
9bf0ef23 525 return logPrefix(
6cd85def 526 ` ${this.chargingStation.stationInfo.chargingStationId} | ATG${
1c9de2b9 527 !isNullOrUndefined(connectorId) ? ` on connector #${connectorId}` : ''
5edd8ba0 528 }:`,
6cd85def 529 );
8b7072dc 530 };
d9ac47ef
JB
531
532 private handleStartTransactionResponse(
533 connectorId: number,
5edd8ba0 534 startResponse: StartTransactionResponse,
d9ac47ef 535 ): void {
e1d9a0f4 536 ++this.connectorsStatus.get(connectorId)!.startTransactionRequests!;
d9ac47ef 537 if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
e1d9a0f4 538 ++this.connectorsStatus.get(connectorId)!.acceptedStartTransactionRequests!;
d9ac47ef 539 } else {
44eb6026 540 logger.warn(`${this.logPrefix(connectorId)} start transaction rejected`);
e1d9a0f4 541 ++this.connectorsStatus.get(connectorId)!.rejectedStartTransactionRequests!;
d9ac47ef
JB
542 }
543 }
6af9012e 544}