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