+ this.connectorsStatus = new Map<number, Status>();
+ this.initializeConnectorsStatus();
+ }
+
+ public static getInstance(
+ chargingStation: ChargingStation
+ ): AutomaticTransactionGenerator | undefined {
+ if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) {
+ AutomaticTransactionGenerator.instances.set(
+ chargingStation.stationInfo.hashId,
+ new AutomaticTransactionGenerator(chargingStation)
+ );
+ }
+ return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo.hashId);
+ }
+
+ public start(): void {
+ if (checkChargingStation(this.chargingStation, this.logPrefix()) === false) {
+ return;
+ }
+ if (this.started === true) {
+ logger.warn(`${this.logPrefix()} is already started`);
+ return;
+ }
+ if (this.starting === true) {
+ logger.warn(`${this.logPrefix()} is already starting`);
+ return;
+ }
+ this.starting = true;
+ this.startConnectors();
+ this.started = true;
+ this.starting = false;
+ }
+
+ public stop(): void {
+ if (this.started === false) {
+ logger.warn(`${this.logPrefix()} is already stopped`);
+ return;
+ }
+ if (this.stopping === true) {
+ logger.warn(`${this.logPrefix()} is already stopping`);
+ return;
+ }
+ this.stopping = true;
+ this.stopConnectors();
+ this.started = false;
+ this.stopping = false;
+ }
+
+ public startConnector(connectorId: number): void {
+ if (checkChargingStation(this.chargingStation, this.logPrefix(connectorId)) === false) {
+ return;
+ }
+ if (this.connectorsStatus.has(connectorId) === false) {
+ logger.error(`${this.logPrefix(connectorId)} starting on non existing connector`);
+ throw new BaseError(`Connector ${connectorId} does not exist`);
+ }
+ if (this.connectorsStatus.get(connectorId)?.start === false) {
+ this.runInAsyncScope(
+ this.internalStartConnector.bind(this) as (
+ this: AutomaticTransactionGenerator,
+ ...args: any[]
+ ) => Promise<void>,
+ this,
+ connectorId
+ ).catch(Constants.EMPTY_FUNCTION);
+ } else if (this.connectorsStatus.get(connectorId)?.start === true) {
+ logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
+ }
+ }
+
+ public stopConnector(connectorId: number): void {
+ if (this.connectorsStatus.has(connectorId) === false) {
+ logger.error(`${this.logPrefix(connectorId)} stopping on non existing connector`);
+ throw new BaseError(`Connector ${connectorId} does not exist`);
+ }
+ if (this.connectorsStatus.get(connectorId)?.start === true) {
+ this.connectorsStatus.get(connectorId).start = false;
+ } else if (this.connectorsStatus.get(connectorId)?.start === false) {
+ logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`);
+ }