fix: make ATG wait for CS/connector availability
[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
JB
322 private async waitChargingStationServiceInitialization(connectorId: number): Promise<void> {
323 if (!this.chargingStation?.ocppRequestService) {
324 logger.info(
325 `${this.logPrefix(
326 connectorId,
327 )} transaction loop waiting for charging station service to be initialized`,
328 );
329 do {
330 await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
331 } while (!this.chargingStation?.ocppRequestService);
332 }
333 }
334
335 private async waitChargingStationAvailable(connectorId: number): Promise<void> {
336 if (!this.chargingStation.isChargingStationAvailable()) {
337 logger.info(
338 `${this.logPrefix(
339 connectorId,
340 )} transaction loop waiting for charging station to be available`,
341 );
342 do {
343 await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
344 } while (!this.chargingStation.isChargingStationAvailable());
345 }
346 }
347
348 private async waitConnectorAvailable(connectorId: number): Promise<void> {
349 if (!this.chargingStation.isConnectorAvailable(connectorId)) {
350 logger.info(
351 `${this.logPrefix(
352 connectorId,
353 )} transaction loop waiting for connector ${connectorId} to be available`,
354 );
355 do {
356 await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
357 } while (!this.chargingStation.isConnectorAvailable(connectorId));
358 }
359 }
360
7807ccf2 361 private initializeConnectorsStatus(): void {
4334db72
JB
362 if (this.chargingStation.hasEvses) {
363 for (const [evseId, evseStatus] of this.chargingStation.evses) {
364 if (evseId > 0) {
365 for (const connectorId of evseStatus.connectors.keys()) {
5ced7e80 366 this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
4334db72
JB
367 }
368 }
369 }
370 } else {
371 for (const connectorId of this.chargingStation.connectors.keys()) {
372 if (connectorId > 0) {
5ced7e80 373 this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
4334db72 374 }
4dff3039
JB
375 }
376 }
72740232
JB
377 }
378
5ced7e80 379 private getConnectorStatus(connectorId: number): Status {
0a0da58d
JB
380 const connectorStatus = this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[
381 connectorId
382 ]
a82d0329
JB
383 ? cloneObject<Status>(
384 this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId],
385 )
bdc9dc79 386 : undefined;
3d20f4db 387 this.resetConnectorStatus(connectorStatus);
5ced7e80
JB
388 return (
389 connectorStatus ?? {
390 start: false,
391 authorizeRequests: 0,
392 acceptedAuthorizeRequests: 0,
393 rejectedAuthorizeRequests: 0,
394 startTransactionRequests: 0,
395 acceptedStartTransactionRequests: 0,
396 rejectedStartTransactionRequests: 0,
397 stopTransactionRequests: 0,
398 acceptedStopTransactionRequests: 0,
399 rejectedStopTransactionRequests: 0,
400 skippedConsecutiveTransactions: 0,
401 skippedTransactions: 0,
402 }
403 );
404 }
405
3d20f4db
JB
406 private resetConnectorStatus(connectorStatus: Status | undefined): void {
407 delete connectorStatus?.startDate;
408 delete connectorStatus?.lastRunDate;
409 delete connectorStatus?.stopDate;
410 delete connectorStatus?.stoppedDate;
411 if (
412 !this.started &&
413 (connectorStatus?.start === true ||
414 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().enable === false)
415 ) {
416 connectorStatus!.start = false;
417 }
418 }
419
e7aeea18 420 private async startTransaction(
5edd8ba0 421 connectorId: number,
0afed85f 422 ): Promise<StartTransactionResponse | undefined> {
aef1b33a
JB
423 const measureId = 'StartTransaction with ATG';
424 const beginId = PerformanceStatistics.beginMeasure(measureId);
e1d9a0f4 425 let startResponse: StartTransactionResponse | undefined;
f911a4af
JB
426 if (this.chargingStation.hasIdTags()) {
427 const idTag = IdTagsCache.getInstance().getIdTag(
e1d9a0f4 428 this.chargingStation.getAutomaticTransactionGeneratorConfiguration().idTagDistribution!,
aaf2bf9c 429 this.chargingStation,
5edd8ba0 430 connectorId,
aaf2bf9c 431 );
5cf9050d 432 const startTransactionLogMsg = `${this.logPrefix(
5edd8ba0 433 connectorId,
ba7965c4 434 )} start transaction with an idTag '${idTag}'`;
ccb1d6e9 435 if (this.getRequireAuthorize()) {
e1d9a0f4 436 ++this.connectorsStatus.get(connectorId)!.authorizeRequests!;
ae725be3 437 if (await OCPPServiceUtils.isIdTagAuthorized(this.chargingStation, connectorId, idTag)) {
e1d9a0f4 438 ++this.connectorsStatus.get(connectorId)!.acceptedAuthorizeRequests!;
5cf9050d 439 logger.info(startTransactionLogMsg);
5fdab605 440 // Start transaction
f7f98c68 441 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
442 StartTransactionRequest,
443 StartTransactionResponse
08f130a0 444 >(this.chargingStation, RequestCommand.START_TRANSACTION, {
ef6fa3fb
JB
445 connectorId,
446 idTag,
447 });
d9ac47ef 448 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
449 PerformanceStatistics.endMeasure(measureId, beginId);
450 return startResponse;
5fdab605 451 }
e1d9a0f4 452 ++this.connectorsStatus.get(connectorId)!.rejectedAuthorizeRequests!;
aef1b33a 453 PerformanceStatistics.endMeasure(measureId, beginId);
0afed85f 454 return startResponse;
ef6076c1 455 }
5cf9050d 456 logger.info(startTransactionLogMsg);
5fdab605 457 // Start transaction
f7f98c68 458 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
459 StartTransactionRequest,
460 StartTransactionResponse
08f130a0 461 >(this.chargingStation, RequestCommand.START_TRANSACTION, {
ef6fa3fb
JB
462 connectorId,
463 idTag,
464 });
d9ac47ef 465 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
466 PerformanceStatistics.endMeasure(measureId, beginId);
467 return startResponse;
6af9012e 468 }
5cf9050d 469 logger.info(`${this.logPrefix(connectorId)} start transaction without an idTag`);
f7f98c68 470 startResponse = await this.chargingStation.ocppRequestService.requestHandler<
ef6fa3fb
JB
471 StartTransactionRequest,
472 StartTransactionResponse
08f130a0 473 >(this.chargingStation, RequestCommand.START_TRANSACTION, { connectorId });
431b6bd5 474 this.handleStartTransactionResponse(connectorId, startResponse);
aef1b33a
JB
475 PerformanceStatistics.endMeasure(measureId, beginId);
476 return startResponse;
6af9012e
JB
477 }
478
e7aeea18
JB
479 private async stopTransaction(
480 connectorId: number,
9ff486f4 481 reason = StopTransactionReason.LOCAL,
e1d9a0f4 482 ): Promise<StopTransactionResponse | undefined> {
aef1b33a
JB
483 const measureId = 'StopTransaction with ATG';
484 const beginId = PerformanceStatistics.beginMeasure(measureId);
e1d9a0f4 485 let stopResponse: StopTransactionResponse | undefined;
6d9876e7 486 if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
49563992
JB
487 logger.info(
488 `${this.logPrefix(
489 connectorId,
490 )} stop transaction with id ${this.chargingStation.getConnectorStatus(connectorId)
491 ?.transactionId}`,
492 );
5e3cb728 493 stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason);
e1d9a0f4 494 ++this.connectorsStatus.get(connectorId)!.stopTransactionRequests!;
0afed85f 495 if (stopResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
e1d9a0f4 496 ++this.connectorsStatus.get(connectorId)!.acceptedStopTransactionRequests!;
6d9876e7 497 } else {
e1d9a0f4 498 ++this.connectorsStatus.get(connectorId)!.rejectedStopTransactionRequests!;
6d9876e7 499 }
0045cef5 500 } else {
1895299d 501 const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
ff581359 502 logger.debug(
ba7965c4 503 `${this.logPrefix(connectorId)} stopping a not started transaction${
1c9de2b9 504 !isNullOrUndefined(transactionId) ? ` with id ${transactionId}` : ''
5edd8ba0 505 }`,
e7aeea18 506 );
0045cef5 507 }
aef1b33a
JB
508 PerformanceStatistics.endMeasure(measureId, beginId);
509 return stopResponse;
c0560973
JB
510 }
511
ccb1d6e9 512 private getRequireAuthorize(): boolean {
ac7f79af
JB
513 return (
514 this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.requireAuthorize ?? true
515 );
ccb1d6e9
JB
516 }
517
8b7072dc 518 private logPrefix = (connectorId?: number): string => {
9bf0ef23 519 return logPrefix(
6cd85def 520 ` ${this.chargingStation.stationInfo.chargingStationId} | ATG${
1c9de2b9 521 !isNullOrUndefined(connectorId) ? ` on connector #${connectorId}` : ''
5edd8ba0 522 }:`,
6cd85def 523 );
8b7072dc 524 };
d9ac47ef
JB
525
526 private handleStartTransactionResponse(
527 connectorId: number,
5edd8ba0 528 startResponse: StartTransactionResponse,
d9ac47ef 529 ): void {
e1d9a0f4 530 ++this.connectorsStatus.get(connectorId)!.startTransactionRequests!;
d9ac47ef 531 if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
e1d9a0f4 532 ++this.connectorsStatus.get(connectorId)!.acceptedStartTransactionRequests!;
d9ac47ef 533 } else {
44eb6026 534 logger.warn(`${this.logPrefix(connectorId)} start transaction rejected`);
e1d9a0f4 535 ++this.connectorsStatus.get(connectorId)!.rejectedStartTransactionRequests!;
d9ac47ef
JB
536 }
537 }
6af9012e 538}