X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=996b9cf9fb6a83694c8b1fbf1eea80f7d9aed7b4;hb=f6591eb9f063490a9b4950ff782c1026281e81bc;hp=d9f548d71c47aa15ee55d4ebf32ccdbde5ffad91;hpb=2035255d4bd926c4acb40acd2b882d2d16174c55;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d9f548d7..996b9cf9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -161,7 +161,7 @@ export class ChargingStation { public idTagsCache: IdTagsCache; public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined; public ocppConfiguration!: ChargingStationOcppConfiguration | undefined; - public wsConnection!: WebSocket | null; + public wsConnection: WebSocket | null; public readonly connectors: Map; public readonly evses: Map; public readonly requests: Map; @@ -193,6 +193,7 @@ export class ChargingStation { this.started = false; this.starting = false; this.stopping = false; + this.wsConnection = null; this.wsConnectionRestarted = false; this.autoReconnectRetryCount = 0; this.index = index; @@ -681,7 +682,7 @@ export class ChargingStation { this.initialize(); this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!); // Restart the ATG - this.stopAutomaticTransactionGenerator(); + this.stopAutomaticTransactionGenerator().catch(() => {}); delete this.automaticTransactionGeneratorConfiguration; if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { this.startAutomaticTransactionGenerator(); @@ -872,13 +873,13 @@ export class ChargingStation { parentPort?.postMessage(buildUpdatedMessage(this)); } - public stopAutomaticTransactionGenerator(connectorIds?: number[]): void { + public async stopAutomaticTransactionGenerator(connectorIds?: number[]): Promise { if (isNotEmptyArray(connectorIds)) { for (const connectorId of connectorIds!) { - this.automaticTransactionGenerator?.stopConnector(connectorId); + await this.automaticTransactionGenerator?.stopConnector(connectorId); } } else { - this.automaticTransactionGenerator?.stop(); + await this.automaticTransactionGenerator?.stop(); } this.saveAutomaticTransactionGeneratorConfiguration(); parentPort?.postMessage(buildUpdatedMessage(this)); @@ -1033,7 +1034,7 @@ export class ChargingStation { } private stopReservationExpirationSetInterval(): void { - if (this.reservationExpirationSetInterval) { + if (!isNullOrUndefined(this.reservationExpirationSetInterval)) { clearInterval(this.reservationExpirationSetInterval); } } @@ -1699,7 +1700,7 @@ export class ChargingStation { const beginId = PerformanceStatistics.beginMeasure(measureId); writeFileSync( this.configurationFile, - JSON.stringify(configurationData, null, 2), + JSON.stringify(configurationData, undefined, 2), 'utf8', ); PerformanceStatistics.endMeasure(measureId, beginId); @@ -2170,7 +2171,7 @@ export class ChargingStation { this.stopHeartbeat(); // Stop ongoing transactions if (this.automaticTransactionGenerator?.started === true) { - this.stopAutomaticTransactionGenerator(); + await this.stopAutomaticTransactionGenerator(); } else { await this.stopRunningTransactions(reason); } @@ -2317,7 +2318,7 @@ export class ChargingStation { this.stopHeartbeat(); // Stop the ATG if needed if (this.getAutomaticTransactionGeneratorConfiguration().stopOnConnectionFailure === true) { - this.stopAutomaticTransactionGenerator(); + await this.stopAutomaticTransactionGenerator(); } if ( this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries()! ||