- logger.info(`${this.logPrefix()} over and lasted for ${Utils.formatDurationMilliSeconds(this.lastRunDate.getTime() - this.startDate.getTime())}. Stopping all transactions`);
- for (const connector in this.chargingStation.connectors) {
- const transactionId = this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionId;
- if (this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionStarted) {
- logger.info(this.logPrefix(Utils.convertToInt(connector)) + ' over. Stop transaction ' + transactionId.toString());
- await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.chargingStation.getTransactionIdTag(transactionId), reason);
+ 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: unknown[]
+ ) => 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`);
+ }
+ }
+
+ private startConnectors(): void {
+ if (
+ this.connectorsStatus?.size > 0 &&
+ this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()
+ ) {
+ this.connectorsStatus.clear();
+ this.initializeConnectorsStatus();
+ }
+ if (this.chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of this.chargingStation.evses) {
+ if (evseId > 0) {
+ for (const connectorId of evseStatus.connectors.keys()) {
+ this.startConnector(connectorId);
+ }
+ }
+ }
+ } else {
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0) {
+ this.startConnector(connectorId);
+ }
+ }
+ }
+ }
+
+ private stopConnectors(): void {
+ if (this.chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of this.chargingStation.evses) {
+ if (evseId > 0) {
+ for (const connectorId of evseStatus.connectors.keys()) {
+ this.stopConnector(connectorId);
+ }
+ }
+ }
+ } else {
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0) {
+ this.stopConnector(connectorId);
+ }