From dd119a6bc8a78464c82e4d11d88e0fdbbae10537 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 May 2021 01:01:14 +0200 Subject: [PATCH] Code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c20ed239..16415737 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -315,9 +315,7 @@ export default class ChargingStation { public resetTransactionOnConnector(connectorId: number): void { this.initTransactionOnConnector(connectorId); - if (this.getConnector(connectorId)?.transactionSetInterval) { - clearInterval(this.getConnector(connectorId).transactionSetInterval); - } + this.stopMeterValues(connectorId); } public addToMessageQueue(message: string): void { @@ -723,6 +721,13 @@ export default class ChargingStation { } } // Start the ATG + this.startAutomaticTransactionGenerator(); + if (this.getEnableStatistics()) { + this.performanceStatistics.start(); + } + } + + private startAutomaticTransactionGenerator() { if (this.stationInfo.AutomaticTransactionGenerator.enable) { if (!this.automaticTransactionGeneration) { this.automaticTransactionGeneration = new AutomaticTransactionGenerator(this); @@ -732,9 +737,6 @@ export default class ChargingStation { void this.automaticTransactionGeneration.start(); } } - if (this.getEnableStatistics()) { - this.performanceStatistics.start(); - } } private async stopMessageSequence(reason: StopTransactionReason = StopTransactionReason.NONE): Promise { @@ -836,6 +838,12 @@ export default class ChargingStation { logger.info(this.logPrefix() + ' Will communicate through URL ' + this.supervisionUrl); } + private stopMeterValues(connectorId: number) { + if (this.getConnector(connectorId)?.transactionSetInterval) { + clearInterval(this.getConnector(connectorId).transactionSetInterval); + } + } + private startAuthorizationFileMonitoring(): void { fs.watch(this.getAuthorizationFile()).on('change', (e) => { try { @@ -861,15 +869,7 @@ export default class ChargingStation { await this.automaticTransactionGeneration.stop(); } // Start the ATG - if (this.stationInfo.AutomaticTransactionGenerator.enable) { - if (!this.automaticTransactionGeneration) { - this.automaticTransactionGeneration = new AutomaticTransactionGenerator(this); - } - if (this.automaticTransactionGeneration.timeToStop) { - // The ATG might sleep - void this.automaticTransactionGeneration.start(); - } - } + this.startAutomaticTransactionGenerator(); // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed } catch (error) { logger.error(this.logPrefix() + ' Charging station template file monitoring error: %j', error); @@ -889,7 +889,7 @@ export default class ChargingStation { this.stationInfo.AutomaticTransactionGenerator.stopOnConnectionFailure && this.automaticTransactionGeneration && !this.automaticTransactionGeneration.timeToStop) { - this.automaticTransactionGeneration.stop().catch(() => { }); + await this.automaticTransactionGeneration.stop(); } if (this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() || this.getAutoReconnectMaxRetries() === -1) { this.autoReconnectRetryCount++; -- 2.34.1