import path from 'path';
export default class ChargingStation {
+ public readonly id: string;
public readonly stationTemplateFile: string;
public authorizedTags: string[];
public stationInfo!: ChargingStationInfo;
private webSocketPingSetInterval!: NodeJS.Timeout;
constructor(index: number, stationTemplateFile: string) {
+ this.id = Utils.generateUUID();
this.index = index;
this.stationTemplateFile = stationTemplateFile;
- this.connectors = new Map<number, ConnectorStatus>();
- this.initialize();
-
this.stopped = false;
this.wsConnectionRestarted = false;
this.autoReconnectRetryCount = 0;
-
+ this.connectors = new Map<number, ConnectorStatus>();
this.requests = new Map<string, CachedRequest>();
this.messageBuffer = new Set<string>();
-
+ this.initialize();
this.authorizedTags = this.getAuthorizedTags();
}
}
public isConnectorAvailable(id: number): boolean {
- return this.getConnectorStatus(id).availability === AvailabilityType.OPERATIVE;
+ return id > 0 && this.getConnectorStatus(id).availability === AvailabilityType.OPERATIVE;
}
public getNumberOfConnectors(): number {
this.wsConfiguredConnectionUrl = new URL(this.getConfiguredSupervisionUrl().href + '/' + this.stationInfo.chargingStationId);
switch (this.getOcppVersion()) {
case OCPPVersion.VERSION_16:
- this.ocppIncomingRequestService = new OCPP16IncomingRequestService(this);
- this.ocppRequestService = new OCPP16RequestService(this, new OCPP16ResponseService(this));
+ this.ocppIncomingRequestService = OCPP16IncomingRequestService.getInstance<OCPP16IncomingRequestService>(this);
+ this.ocppRequestService = OCPP16RequestService.getInstance<OCPP16RequestService>(this, OCPP16ResponseService.getInstance<OCPP16ResponseService>(this));
break;
default:
this.handleUnsupportedVersion(this.getOcppVersion());
}
this.stationInfo.powerDivider = this.getPowerDivider();
if (this.getEnableStatistics()) {
- this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId, this.wsConnectionUrl);
+ this.performanceStatistics = PerformanceStatistics.getInstance(this.id, this.stationInfo.chargingStationId, this.wsConnectionUrl);
}
}
this.stopHeartbeat();
// Stop the ATG
if (this.stationInfo.AutomaticTransactionGenerator.enable &&
- this.automaticTransactionGenerator &&
- this.automaticTransactionGenerator.started) {
+ this.automaticTransactionGenerator?.started) {
this.automaticTransactionGenerator.stop();
} else {
for (const connectorId of this.connectors.keys()) {
// Stop the ATG if needed
if (this.stationInfo.AutomaticTransactionGenerator.enable &&
this.stationInfo.AutomaticTransactionGenerator.stopOnConnectionFailure &&
- this.automaticTransactionGenerator &&
- this.automaticTransactionGenerator.started) {
+ this.automaticTransactionGenerator?.started) {
this.automaticTransactionGenerator.stop();
}
if (this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() || this.getAutoReconnectMaxRetries() === -1) {