public started: boolean;
public starting: boolean;
public authorizedTagsCache: AuthorizedTagsCache;
- public automaticTransactionGenerator!: AutomaticTransactionGenerator;
- public ocppConfiguration!: ChargingStationOcppConfiguration | null;
+ public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined;
+ public ocppConfiguration!: ChargingStationOcppConfiguration | undefined;
public wsConnection!: WebSocket | null;
public readonly connectors: Map<number, ConnectorStatus>;
public readonly requests: Map<string, CachedRequest>;
- public performanceStatistics!: PerformanceStatistics;
+ public performanceStatistics!: PerformanceStatistics | undefined;
public heartbeatSetInterval!: NodeJS.Timeout;
public ocppRequestService!: OCPPRequestService;
public bootNotificationRequest!: BootNotificationRequest;
if (this.starting === false) {
this.starting = true;
if (this.getEnableStatistics() === true) {
- this.performanceStatistics.start();
+ this.performanceStatistics?.start();
}
this.openWSConnection();
// Monitor charging station template file
this.startAutomaticTransactionGenerator();
}
if (this.getEnableStatistics() === true) {
- this.performanceStatistics.restart();
+ this.performanceStatistics?.restart();
} else {
- this.performanceStatistics.stop();
+ this.performanceStatistics?.stop();
}
// FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
} catch (error) {
await this.stopMessageSequence(reason);
this.closeWSConnection();
if (this.getEnableStatistics() === true) {
- this.performanceStatistics.stop();
+ this.performanceStatistics?.stop();
}
this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash);
this.templateFileWatcher?.close();
);
if (!Utils.isEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
- this.automaticTransactionGenerator.startConnector(connectorId);
+ this.automaticTransactionGenerator?.startConnector(connectorId);
}
} else {
- this.automaticTransactionGenerator.start();
+ this.automaticTransactionGenerator?.start();
}
parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
}
stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
ChargingStationUtils.createSerialNumber(stationTemplate, stationInfo);
if (!Utils.isEmptyArray(stationTemplate?.power)) {
- stationTemplate.power = stationTemplate?.power as number[];
+ stationTemplate.power = stationTemplate.power as number[];
const powerArrayRandomIndex = Math.floor(Utils.secureRandom() * stationTemplate.power.length);
stationInfo.maximumPower =
stationTemplate?.powerUnit === PowerUnits.KILO_WATT
? stationTemplate.power[powerArrayRandomIndex] * 1000
: stationTemplate.power[powerArrayRandomIndex];
} else {
- stationTemplate.power = stationTemplate.power as number;
+ stationTemplate.power = stationTemplate?.power as number;
stationInfo.maximumPower =
stationTemplate?.powerUnit === PowerUnits.KILO_WATT
? stationTemplate.power * 1000
return stationInfo;
}
- private getStationInfoFromFile(): ChargingStationInfo | null {
- let stationInfo: ChargingStationInfo | null = null;
+ private getStationInfoFromFile(): ChargingStationInfo | undefined {
+ let stationInfo: ChargingStationInfo | undefined;
this.getStationInfoPersistentConfiguration() &&
- (stationInfo = this.getConfigurationFromFile()?.stationInfo ?? null);
+ (stationInfo = this.getConfigurationFromFile()?.stationInfo);
stationInfo && ChargingStationUtils.createStationInfoHash(stationInfo);
return stationInfo;
}
private getStationInfo(): ChargingStationInfo {
const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate();
- const stationInfoFromFile: ChargingStationInfo | null = this.getStationInfoFromFile();
+ const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile();
// Priority: charging station info from template > charging station info from configuration file > charging station info attribute
if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
if (this.stationInfo?.infoHash === stationInfoFromFile?.infoHash) {
}
}
- private getConfigurationFromFile(): ChargingStationConfiguration | null {
- let configuration: ChargingStationConfiguration | null = null;
+ private getConfigurationFromFile(): ChargingStationConfiguration | undefined {
+ let configuration: ChargingStationConfiguration | undefined;
if (this.configurationFile && fs.existsSync(this.configurationFile)) {
try {
if (this.sharedLRUCache.hasChargingStationConfiguration(this.configurationFileHash)) {
}
}
- private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration | null {
- return this.getTemplateFromFile()?.Configuration ?? null;
+ private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration | undefined {
+ return this.getTemplateFromFile()?.Configuration;
}
- private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | null {
- let configuration: ChargingStationConfiguration | null = null;
+ private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | undefined {
+ let configuration: ChargingStationConfiguration | undefined;
if (this.getOcppPersistentConfiguration() === true) {
const configurationFromFile = this.getConfigurationFromFile();
configuration = configurationFromFile?.configurationKey && configurationFromFile;
return configuration;
}
- private getOcppConfiguration(): ChargingStationOcppConfiguration | null {
- let ocppConfiguration: ChargingStationOcppConfiguration | null =
+ private getOcppConfiguration(): ChargingStationOcppConfiguration | undefined {
+ let ocppConfiguration: ChargingStationOcppConfiguration | undefined =
this.getOcppConfigurationFromFile();
if (!ocppConfiguration) {
ocppConfiguration = this.getOcppConfigurationFromTemplate();
case MessageType.CALL_MESSAGE:
[, , commandName, commandPayload] = request as IncomingRequest;
if (this.getEnableStatistics() === true) {
- this.performanceStatistics.addRequestStatistic(commandName, messageType);
+ this.performanceStatistics?.addRequestStatistic(commandName, messageType);
}
logger.debug(
`${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
}
}
- private getAutomaticTransactionGeneratorConfigurationFromTemplate(): AutomaticTransactionGeneratorConfiguration | null {
- return this.getTemplateFromFile()?.AutomaticTransactionGenerator ?? null;
+ private getAutomaticTransactionGeneratorConfigurationFromTemplate():
+ | AutomaticTransactionGeneratorConfiguration
+ | undefined {
+ return this.getTemplateFromFile()?.AutomaticTransactionGenerator;
}
private initializeConnectorStatus(connectorId: number): void {