+ 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: 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);
+ }
+ }
+ }
+ }
+
+ private async internalStartConnector(connectorId: number): Promise<void> {
+ this.setStartConnectorStatus(connectorId);
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} started on connector and will run for ${formatDurationMilliSeconds(
+ this.connectorsStatus.get(connectorId)!.stopDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
+ )}`,
+ );
+ while (this.connectorsStatus.get(connectorId)?.start === true) {
+ if (new Date() > this.connectorsStatus.get(connectorId)!.stopDate!) {
+ this.stopConnector(connectorId);
+ break;
+ }
+ if (this.chargingStation.inAcceptedState() === false) {
+ logger.error(
+ `${this.logPrefix(
+ connectorId,
+ )} entered in transaction loop while the charging station is not in accepted state`,
+ );
+ this.stopConnector(connectorId);