X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FChargingStation.ts;h=92fbb80c6e21bde391c74ffccdd52100a38bd26a;hb=48c7e1d6db4b3cbf82d17e191b2255066c462a71;hp=df029c3a6b8245963839d4c093442985bd537253;hpb=a807045be19c1ed4996a44d8c2c8774e926dc6dc;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index df029c3a..92fbb80c 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -134,6 +134,7 @@ import { buildUpdatedMessage, cloneObject, convertToBoolean, + convertToDate, convertToInt, exponentialDelay, formatDurationMilliSeconds, @@ -143,8 +144,6 @@ import { handleFileException, isNotEmptyArray, isNotEmptyString, - isNullOrUndefined, - isUndefined, logPrefix, logger, min, @@ -158,7 +157,7 @@ import { export class ChargingStation extends EventEmitter { public readonly index: number public readonly templateFile: string - public stationInfo!: ChargingStationInfo + public stationInfo?: ChargingStationInfo public started: boolean public starting: boolean public idTagsCache: IdTagsCache @@ -171,9 +170,9 @@ export class ChargingStation extends EventEmitter { public performanceStatistics!: PerformanceStatistics | undefined public heartbeatSetInterval?: NodeJS.Timeout public ocppRequestService!: OCPPRequestService - public bootNotificationRequest!: BootNotificationRequest - public bootNotificationResponse!: BootNotificationResponse | undefined - public powerDivider!: number + public bootNotificationRequest?: BootNotificationRequest + public bootNotificationResponse?: BootNotificationResponse + public powerDivider?: number private stopping: boolean private configurationFile!: string private configurationFileHash!: string @@ -229,19 +228,23 @@ export class ChargingStation extends EventEmitter { return new URL( `${ this.stationInfo?.supervisionUrlOcppConfiguration === true && - isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) && + isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion isNotEmptyString(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)?.value) ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)!.value : this.configuredSupervisionUrl.href - }/${this.stationInfo.chargingStationId}` + }/${this.stationInfo?.chargingStationId}` ) } public logPrefix = (): string => { - if (isNotEmptyString(this?.stationInfo?.chargingStationId)) { - return logPrefix(` ${this?.stationInfo?.chargingStationId} |`) + if ( + this instanceof ChargingStation && + this.stationInfo != null && + isNotEmptyString(this.stationInfo.chargingStationId) + ) { + return logPrefix(` ${this.stationInfo.chargingStationId} |`) } let stationTemplate: ChargingStationTemplate | undefined try { @@ -256,11 +259,12 @@ export class ChargingStation extends EventEmitter { public hasIdTags (): boolean { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return isNotEmptyArray(this.idTagsCache.getIdTags(getIdTagsFile(this.stationInfo)!)) + return isNotEmptyArray(this.idTagsCache.getIdTags(getIdTagsFile(this.stationInfo!)!)) } public getNumberOfPhases (stationInfo?: ChargingStationInfo): number { - const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const localStationInfo = stationInfo ?? this.stationInfo! switch (this.getCurrentOutType(stationInfo)) { case CurrentType.AC: return localStationInfo.numberOfPhases ?? 3 @@ -270,23 +274,23 @@ export class ChargingStation extends EventEmitter { } public isWebSocketConnectionOpened (): boolean { - return this?.wsConnection?.readyState === WebSocket.OPEN + return this.wsConnection?.readyState === WebSocket.OPEN } public inUnknownState (): boolean { - return isNullOrUndefined(this?.bootNotificationResponse?.status) + return this.bootNotificationResponse?.status == null } public inPendingState (): boolean { - return this?.bootNotificationResponse?.status === RegistrationStatusEnumType.PENDING + return this.bootNotificationResponse?.status === RegistrationStatusEnumType.PENDING } public inAcceptedState (): boolean { - return this?.bootNotificationResponse?.status === RegistrationStatusEnumType.ACCEPTED + return this.bootNotificationResponse?.status === RegistrationStatusEnumType.ACCEPTED } public inRejectedState (): boolean { - return this?.bootNotificationResponse?.status === RegistrationStatusEnumType.REJECTED + return this.bootNotificationResponse?.status === RegistrationStatusEnumType.REJECTED } public isRegistered (): boolean { @@ -347,10 +351,11 @@ export class ChargingStation extends EventEmitter { public getConnectorMaximumAvailablePower (connectorId: number): number { let connectorAmperageLimitationPowerLimit: number | undefined + const amperageLimitation = this.getAmperageLimitation() if ( - !isNullOrUndefined(this.getAmperageLimitation()) && + amperageLimitation != null && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getAmperageLimitation()! < this.stationInfo.maximumAmperage! + amperageLimitation < this.stationInfo!.maximumAmperage! ) { connectorAmperageLimitationPowerLimit = (this.stationInfo?.currentOutType === CurrentType.AC @@ -358,16 +363,16 @@ export class ChargingStation extends EventEmitter { this.getNumberOfPhases(), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.stationInfo.voltageOut!, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getAmperageLimitation()! * + amperageLimitation * (this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors()) ) : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - DCElectricUtils.power(this.stationInfo.voltageOut!, this.getAmperageLimitation()!)) / - this.powerDivider + DCElectricUtils.power(this.stationInfo!.voltageOut!, amperageLimitation)) / + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.powerDivider! } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const connectorMaximumPower = this.stationInfo.maximumPower! / this.powerDivider + const connectorMaximumPower = this.stationInfo!.maximumPower! / this.powerDivider! const connectorChargingProfilesPowerLimit = getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId) return min( @@ -423,8 +428,10 @@ export class ChargingStation extends EventEmitter { return numberOfRunningTransactions } - public getConnectorIdByTransactionId (transactionId: number): number | undefined { - if (this.hasEvses) { + public getConnectorIdByTransactionId (transactionId: number | undefined): number | undefined { + if (transactionId == null) { + return undefined + } else if (this.hasEvses) { for (const evseStatus of this.evses.values()) { for (const [connectorId, connectorStatus] of evseStatus.connectors) { if (connectorStatus.transactionId === transactionId) { @@ -442,19 +449,18 @@ export class ChargingStation extends EventEmitter { } public getEnergyActiveImportRegisterByTransactionId ( - transactionId: number, + transactionId: number | undefined, rounded = false ): number { return this.getEnergyActiveImportRegister( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)!)!, + this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)!), rounded ) } public getEnergyActiveImportRegisterByConnectorId (connectorId: number, rounded = false): number { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId)!, rounded) + return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId), rounded) } public getAuthorizeRemoteTxRequests (): boolean { @@ -496,12 +502,13 @@ export class ChargingStation extends EventEmitter { public setSupervisionUrl (url: string): void { if ( this.stationInfo?.supervisionUrlOcppConfiguration === true && - isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) + isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) ) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey!, url) } else { - this.stationInfo.supervisionUrls = url + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.stationInfo!.supervisionUrls = url this.saveStationInfo() this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl() } @@ -512,7 +519,7 @@ export class ChargingStation extends EventEmitter { this.heartbeatSetInterval = setInterval(() => { this.ocppRequestService .requestHandler(this, RequestCommand.HEARTBEAT) - .catch((error) => { + .catch(error => { logger.error( `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`, error @@ -556,21 +563,22 @@ export class ChargingStation extends EventEmitter { logger.error(`${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId}`) return } - if (this.getConnectorStatus(connectorId) == null) { + const connectorStatus = this.getConnectorStatus(connectorId) + if (connectorStatus == null) { logger.error( `${this.logPrefix()} Trying to start MeterValues on non existing connector id ${connectorId}` ) return } - if (this.getConnectorStatus(connectorId)?.transactionStarted === false) { + if (connectorStatus.transactionStarted === false) { logger.error( `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction started` ) return } else if ( - this.getConnectorStatus(connectorId)?.transactionStarted === true && - isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionId) + connectorStatus.transactionStarted === true && + connectorStatus.transactionId == null ) { logger.error( `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction id` @@ -578,13 +586,12 @@ export class ChargingStation extends EventEmitter { return } if (interval > 0) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getConnectorStatus(connectorId)!.transactionSetInterval = setInterval(() => { + connectorStatus.transactionSetInterval = setInterval(() => { const meterValue = buildMeterValue( this, connectorId, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getConnectorStatus(connectorId)!.transactionId!, + connectorStatus.transactionId!, interval ) this.ocppRequestService @@ -593,11 +600,11 @@ export class ChargingStation extends EventEmitter { RequestCommand.METER_VALUES, { connectorId, - transactionId: this.getConnectorStatus(connectorId)?.transactionId, + transactionId: connectorStatus.transactionId, meterValue: [meterValue] } ) - .catch((error) => { + .catch(error => { logger.error( `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`, error @@ -614,8 +621,9 @@ export class ChargingStation extends EventEmitter { } public stopMeterValues (connectorId: number): void { - if (this.getConnectorStatus(connectorId)?.transactionSetInterval != null) { - clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval) + const connectorStatus = this.getConnectorStatus(connectorId) + if (connectorStatus?.transactionSetInterval != null) { + clearInterval(connectorStatus.transactionSetInterval) } } @@ -645,11 +653,11 @@ export class ChargingStation extends EventEmitter { // Initialize this.initialize() // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!) + this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo!)!) // Restart the ATG this.stopAutomaticTransactionGenerator() delete this.automaticTransactionGeneratorConfiguration - if (this.getAutomaticTransactionGeneratorConfiguration().enable) { + if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { this.startAutomaticTransactionGenerator() } if (this.stationInfo?.enableStatistics === true) { @@ -706,7 +714,7 @@ export class ChargingStation extends EventEmitter { public async reset (reason?: StopTransactionReason): Promise { await this.stop(reason) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await sleep(this.stationInfo.resetTime!) + await sleep(this.stationInfo!.resetTime!) this.initialize() this.start() } @@ -735,16 +743,13 @@ export class ChargingStation extends EventEmitter { if (!checkChargingStation(this, this.logPrefix())) { return } - if ( - !isNullOrUndefined(this.stationInfo.supervisionUser) && - !isNullOrUndefined(this.stationInfo.supervisionPassword) - ) { + if (this.stationInfo?.supervisionUser != null && this.stationInfo.supervisionPassword != null) { options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}` } - if (params?.closeOpened === true) { + if (params.closeOpened === true) { this.closeWSConnection() } - if (params?.terminateOpened === true) { + if (params.terminateOpened === true) { this.terminateWSConnection() } @@ -795,8 +800,10 @@ export class ChargingStation extends EventEmitter { } } - public getAutomaticTransactionGeneratorConfiguration (): AutomaticTransactionGeneratorConfiguration { - if (isNullOrUndefined(this.automaticTransactionGeneratorConfiguration)) { + public getAutomaticTransactionGeneratorConfiguration (): + | AutomaticTransactionGeneratorConfiguration + | undefined { + if (this.automaticTransactionGeneratorConfiguration == null) { let automaticTransactionGeneratorConfiguration: | AutomaticTransactionGeneratorConfiguration | undefined @@ -808,7 +815,7 @@ export class ChargingStation extends EventEmitter { stationConfiguration?.automaticTransactionGenerator != null ) { automaticTransactionGeneratorConfiguration = - stationConfiguration?.automaticTransactionGenerator + stationConfiguration.automaticTransactionGenerator } else { automaticTransactionGeneratorConfiguration = stationTemplate?.AutomaticTransactionGenerator } @@ -817,8 +824,7 @@ export class ChargingStation extends EventEmitter { ...automaticTransactionGeneratorConfiguration } } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return this.automaticTransactionGeneratorConfiguration! + return this.automaticTransactionGeneratorConfiguration } public getAutomaticTransactionGeneratorStatuses (): Status[] | undefined { @@ -859,14 +865,13 @@ export class ChargingStation extends EventEmitter { const transactionId = this.getConnectorStatus(connectorId)?.transactionId if ( this.stationInfo?.beginEndMeterValues === true && - this.stationInfo?.ocppStrictCompliance === true && - this.stationInfo?.outOfOrderEndMeterValues === false + this.stationInfo.ocppStrictCompliance === true && + this.stationInfo.outOfOrderEndMeterValues === false ) { const transactionEndMeterValue = buildTransactionEndMeterValue( this, connectorId, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getEnergyActiveImportRegisterByTransactionId(transactionId!) + this.getEnergyActiveImportRegisterByTransactionId(transactionId) ) await this.ocppRequestService.requestHandler( this, @@ -883,9 +888,8 @@ export class ChargingStation extends EventEmitter { StopTransactionResponse >(this, RequestCommand.STOP_TRANSACTION, { transactionId, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId!, true), - ...(isNullOrUndefined(reason) && { reason }) + meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true), + ...(reason != null && { reason }) }) } @@ -948,14 +952,14 @@ export class ChargingStation extends EventEmitter { if (this.hasEvses) { for (const evseStatus of this.evses.values()) { for (const connectorStatus of evseStatus.connectors.values()) { - if (connectorStatus?.reservation?.[filterKey] === value) { + if (connectorStatus.reservation?.[filterKey] === value) { return connectorStatus.reservation } } } } else { for (const connectorStatus of this.connectors.values()) { - if (connectorStatus?.reservation?.[filterKey] === value) { + if (connectorStatus.reservation?.[filterKey] === value) { return connectorStatus.reservation } } @@ -968,20 +972,15 @@ export class ChargingStation extends EventEmitter { connectorId?: number ): boolean { const reservation = this.getReservationBy('reservationId', reservationId) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const reservationExists = !isUndefined(reservation) && !hasReservationExpired(reservation!) + const reservationExists = reservation !== undefined && !hasReservationExpired(reservation) if (arguments.length === 1) { return !reservationExists } else if (arguments.length > 1) { - const userReservation = !isUndefined(idTag) - ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getReservationBy('idTag', idTag!) - : undefined + const userReservation = + idTag !== undefined ? this.getReservationBy('idTag', idTag) : undefined const userReservationExists = - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - !isUndefined(userReservation) && !hasReservationExpired(userReservation!) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0 + userReservation !== undefined && !hasReservationExpired(userReservation) + const notConnectorZero = connectorId === undefined ? true : connectorId > 0 const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0 return ( !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable @@ -1046,7 +1045,7 @@ export class ChargingStation extends EventEmitter { this.wsConnection?.send(message, (error?: Error) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!) - if (isNullOrUndefined(error)) { + if (error == null) { logger.debug( `${this.logPrefix()} >> Buffered ${getMessageTypeString( messageType @@ -1095,36 +1094,36 @@ export class ChargingStation extends EventEmitter { private getStationInfoFromTemplate (): ChargingStationInfo { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const stationTemplate: ChargingStationTemplate = this.getTemplateFromFile()! + const stationTemplate = this.getTemplateFromFile()! checkTemplate(stationTemplate, this.logPrefix(), this.templateFile) const warnTemplateKeysDeprecationOnce = once(warnTemplateKeysDeprecation, this) warnTemplateKeysDeprecationOnce(stationTemplate, this.logPrefix(), this.templateFile) - if (stationTemplate?.Connectors != null) { + if (stationTemplate.Connectors != null) { checkConnectorsConfiguration(stationTemplate, this.logPrefix(), this.templateFile) } - const stationInfo: ChargingStationInfo = stationTemplateToStationInfo(stationTemplate) + const stationInfo = stationTemplateToStationInfo(stationTemplate) stationInfo.hashId = getHashId(this.index, stationTemplate) stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate) - stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16 + stationInfo.ocppVersion = stationTemplate.ocppVersion ?? OCPPVersion.VERSION_16 createSerialNumber(stationTemplate, stationInfo) stationInfo.voltageOut = this.getVoltageOut(stationInfo) - if (isNotEmptyArray(stationTemplate?.power)) { + if (isNotEmptyArray(stationTemplate.power)) { stationTemplate.power = stationTemplate.power as number[] const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length) stationInfo.maximumPower = - stationTemplate?.powerUnit === PowerUnits.KILO_WATT + 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.powerUnit === PowerUnits.KILO_WATT ? stationTemplate.power * 1000 : stationTemplate.power } stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo) stationInfo.firmwareVersionPattern = - stationTemplate?.firmwareVersionPattern ?? Constants.SEMVER_PATTERN + stationTemplate.firmwareVersionPattern ?? Constants.SEMVER_PATTERN if ( isNotEmptyString(stationInfo.firmwareVersion) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -1143,12 +1142,12 @@ export class ChargingStation extends EventEmitter { }, reset: true }, - stationTemplate?.firmwareUpgrade ?? {} + stationTemplate.firmwareUpgrade ?? {} ) - stationInfo.resetTime = !isNullOrUndefined(stationTemplate?.resetTime) - ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - secondsToMilliseconds(stationTemplate.resetTime!) - : Constants.CHARGING_STATION_DEFAULT_RESET_TIME + stationInfo.resetTime = + stationTemplate.resetTime != null + ? secondsToMilliseconds(stationTemplate.resetTime) + : Constants.CHARGING_STATION_DEFAULT_RESET_TIME return stationInfo } @@ -1159,7 +1158,7 @@ export class ChargingStation extends EventEmitter { if (stationInfoPersistentConfiguration) { stationInfo = this.getConfigurationFromFile()?.stationInfo if (stationInfo != null) { - delete stationInfo?.infoHash + delete stationInfo.infoHash } } return stationInfo @@ -1167,21 +1166,22 @@ export class ChargingStation extends EventEmitter { private getStationInfo (): ChargingStationInfo { const defaultStationInfo = Constants.DEFAULT_STATION_INFO - const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate() - const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile( - stationInfoFromTemplate?.stationInfoPersistentConfiguration + const stationInfoFromTemplate = this.getStationInfoFromTemplate() + const stationInfoFromFile = this.getStationInfoFromFile( + stationInfoFromTemplate.stationInfoPersistentConfiguration ) // Priority: // 1. charging station info from template // 2. charging station info from configuration file - if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return { ...defaultStationInfo, ...stationInfoFromFile! } + if ( + stationInfoFromFile != null && + stationInfoFromFile.templateHash === stationInfoFromTemplate.templateHash + ) { + return { ...defaultStationInfo, ...stationInfoFromFile } } stationInfoFromFile != null && propagateSerialNumber( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.getTemplateFromFile()!, + this.getTemplateFromFile(), stationInfoFromFile, stationInfoFromTemplate ) @@ -1210,8 +1210,7 @@ export class ChargingStation extends EventEmitter { ) const stationConfiguration = this.getConfigurationFromFile() if ( - stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash && - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + stationConfiguration?.stationInfo?.templateHash === stationTemplate.templateHash && (stationConfiguration?.connectorsStatus != null || stationConfiguration?.evsesStatus != null) ) { checkConfiguration(stationConfiguration, this.logPrefix(), this.configurationFile) @@ -1225,7 +1224,7 @@ export class ChargingStation extends EventEmitter { isNotEmptyString(this.stationInfo.firmwareVersion) && isNotEmptyString(this.stationInfo.firmwareVersionPattern) ) { - const patternGroup: number | undefined = + const patternGroup = this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ?? this.stationInfo.firmwareVersion?.split('.').length // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -1234,40 +1233,43 @@ export class ChargingStation extends EventEmitter { .exec(this.stationInfo.firmwareVersion!) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ?.slice(1, patternGroup! + 1) - if (!isNullOrUndefined(match)) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const patchLevelIndex = match!.length - 1 - // prettier-ignore - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - match![patchLevelIndex] = (convertToInt(match![patchLevelIndex]) + - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.stationInfo.firmwareUpgrade!.versionUpgrade!.step!).toString() - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.stationInfo.firmwareVersion = match!.join('.') + if (match != null) { + const patchLevelIndex = match.length - 1 + match[patchLevelIndex] = ( + convertToInt(match[patchLevelIndex]) + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.stationInfo.firmwareUpgrade!.versionUpgrade!.step! + ).toString() + this.stationInfo.firmwareVersion = match.join('.') } } this.saveStationInfo() this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl() - if (this.stationInfo?.enableStatistics === true) { + if (this.stationInfo.enableStatistics === true) { this.performanceStatistics = PerformanceStatistics.getInstance( this.stationInfo.hashId, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.stationInfo.chargingStationId!, + this.stationInfo.chargingStationId, this.configuredSupervisionUrl ) } - this.bootNotificationRequest = createBootNotificationRequest(this.stationInfo) + const bootNotificationRequest = createBootNotificationRequest(this.stationInfo) + if (bootNotificationRequest == null) { + const errorMsg = 'Error while creating boot notification request' + logger.error(`${this.logPrefix()} ${errorMsg}`) + throw new BaseError(errorMsg) + } + this.bootNotificationRequest = bootNotificationRequest this.powerDivider = this.getPowerDivider() // OCPP configuration this.ocppConfiguration = this.getOcppConfiguration() this.initializeOcppConfiguration() this.initializeOcppServices() this.once(ChargingStationEvents.accepted, () => { - this.startMessageSequence().catch((error) => { + this.startMessageSequence().catch(error => { logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error) }) }) - if (this.stationInfo?.autoRegister === true) { + if (this.stationInfo.autoRegister === true) { this.bootNotificationResponse = { currentTime: new Date(), interval: millisecondsToSeconds(this.getHeartbeatInterval()), @@ -1301,17 +1303,17 @@ export class ChargingStation extends EventEmitter { } private initializeOcppConfiguration (): void { - if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartbeatInterval))) { + if (getConfigurationKey(this, StandardParametersKey.HeartbeatInterval) == null) { addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0') } - if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartBeatInterval))) { + if (getConfigurationKey(this, StandardParametersKey.HeartBeatInterval) == null) { addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false }) } if ( this.stationInfo?.supervisionUrlOcppConfiguration === true && - isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) && + isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - isNullOrUndefined(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)) + getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) == null ) { addConfigurationKey( this, @@ -1322,9 +1324,9 @@ export class ChargingStation extends EventEmitter { ) } else if ( this.stationInfo?.supervisionUrlOcppConfiguration === false && - isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) && + isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - !isNullOrUndefined(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!)) + getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) != null ) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion deleteConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!, { save: false }) @@ -1332,20 +1334,18 @@ export class ChargingStation extends EventEmitter { if ( isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - isNullOrUndefined(getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)) + getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) == null ) { addConfigurationKey( this, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.stationInfo.amperageLimitationOcppKey!, + this.stationInfo!.amperageLimitationOcppKey!, // prettier-ignore // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (this.stationInfo.maximumAmperage! * getAmperageLimitationUnitDivider(this.stationInfo)).toString() + (this.stationInfo!.maximumAmperage! * getAmperageLimitationUnitDivider(this.stationInfo)).toString() ) } - if ( - isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)) - ) { + if (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) { addConfigurationKey( this, StandardParametersKey.SupportedFeatureProfiles, @@ -1359,18 +1359,14 @@ export class ChargingStation extends EventEmitter { { readonly: true }, { overwrite: true } ) - if ( - isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData)) - ) { + if (getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData) == null) { addConfigurationKey( this, StandardParametersKey.MeterValuesSampledData, MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER ) } - if ( - isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation)) - ) { + if (getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation) == null) { const connectorsPhaseRotation: string[] = [] if (this.hasEvses) { for (const evseStatus of this.evses.values()) { @@ -1395,18 +1391,16 @@ export class ChargingStation extends EventEmitter { connectorsPhaseRotation.toString() ) } - if ( - isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests)) - ) { + if (getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests) == null) { addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true') } if ( - isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled)) && + getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) == null && hasFeatureProfile(this, SupportedFeatureProfiles.LocalAuthListManagement) === true ) { addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false') } - if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut))) { + if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) == null) { addConfigurationKey( this, StandardParametersKey.ConnectionTimeOut, @@ -1417,11 +1411,11 @@ export class ChargingStation extends EventEmitter { } private initializeConnectorsOrEvsesFromFile (configuration: ChargingStationConfiguration): void { - if (configuration?.connectorsStatus != null && configuration?.evsesStatus == null) { + if (configuration.connectorsStatus != null && configuration.evsesStatus == null) { for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) { this.connectors.set(connectorId, cloneObject(connectorStatus)) } - } else if (configuration?.evsesStatus != null && configuration?.connectorsStatus == null) { + } else if (configuration.evsesStatus != null && configuration.connectorsStatus == null) { for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) { const evseStatus = cloneObject(evseStatusConfiguration) delete evseStatus.connectorsStatus @@ -1436,7 +1430,7 @@ export class ChargingStation extends EventEmitter { ) }) } - } else if (configuration?.evsesStatus != null && configuration?.connectorsStatus != null) { + } else if (configuration.evsesStatus != null && configuration.connectorsStatus != null) { const errorMsg = `Connectors and evses defined at the same time in configuration file ${this.configurationFile}` logger.error(`${this.logPrefix()} ${errorMsg}`) throw new BaseError(errorMsg) @@ -1448,11 +1442,11 @@ export class ChargingStation extends EventEmitter { } private initializeConnectorsOrEvsesFromTemplate (stationTemplate: ChargingStationTemplate): void { - if (stationTemplate?.Connectors != null && stationTemplate?.Evses == null) { + if (stationTemplate.Connectors != null && stationTemplate.Evses == null) { this.initializeConnectorsFromTemplate(stationTemplate) - } else if (stationTemplate?.Evses != null && stationTemplate?.Connectors == null) { + } else if (stationTemplate.Evses != null && stationTemplate.Connectors == null) { this.initializeEvsesFromTemplate(stationTemplate) - } else if (stationTemplate?.Evses != null && stationTemplate?.Connectors != null) { + } else if (stationTemplate.Evses != null && stationTemplate.Connectors != null) { const errorMsg = `Connectors and evses defined at the same time in template file ${this.templateFile}` logger.error(`${this.logPrefix()} ${errorMsg}`) throw new BaseError(errorMsg) @@ -1464,45 +1458,46 @@ export class ChargingStation extends EventEmitter { } private initializeConnectorsFromTemplate (stationTemplate: ChargingStationTemplate): void { - if (stationTemplate?.Connectors == null && this.connectors.size === 0) { + if (stationTemplate.Connectors == null && this.connectors.size === 0) { const errorMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined` logger.error(`${this.logPrefix()} ${errorMsg}`) throw new BaseError(errorMsg) } - if (stationTemplate?.Connectors?.[0] == null) { + if (stationTemplate.Connectors?.[0] == null) { logger.warn( `${this.logPrefix()} Charging station information from template ${ this.templateFile } with no connector id 0 configuration` ) } - if (stationTemplate?.Connectors != null) { + if (stationTemplate.Connectors != null) { const { configuredMaxConnectors, templateMaxConnectors, templateMaxAvailableConnectors } = checkConnectorsConfiguration(stationTemplate, this.logPrefix(), this.templateFile) const connectorsConfigHash = createHash(Constants.DEFAULT_HASH_ALGORITHM) .update( - `${JSON.stringify(stationTemplate?.Connectors)}${configuredMaxConnectors.toString()}` + `${JSON.stringify(stationTemplate.Connectors)}${configuredMaxConnectors.toString()}` ) .digest('hex') const connectorsConfigChanged = - this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash - if (this.connectors?.size === 0 || connectorsConfigChanged) { + this.connectors.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash + if (this.connectors.size === 0 || connectorsConfigChanged) { connectorsConfigChanged && this.connectors.clear() this.connectorsConfigurationHash = connectorsConfigHash if (templateMaxConnectors > 0) { for (let connectorId = 0; connectorId <= configuredMaxConnectors; connectorId++) { if ( connectorId === 0 && - (stationTemplate?.Connectors?.[connectorId] == null || + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + (stationTemplate.Connectors[connectorId] == null || !this.getUseConnectorId0(stationTemplate)) ) { continue } const templateConnectorId = - connectorId > 0 && stationTemplate?.randomConnectors === true + connectorId > 0 && stationTemplate.randomConnectors === true ? getRandomInteger(templateMaxAvailableConnectors, 1) : connectorId - const connectorStatus = stationTemplate?.Connectors[templateConnectorId] + const connectorStatus = stationTemplate.Connectors[templateConnectorId] checkStationInfoConnectorStatus( templateConnectorId, connectorStatus, @@ -1531,48 +1526,48 @@ export class ChargingStation extends EventEmitter { } private initializeEvsesFromTemplate (stationTemplate: ChargingStationTemplate): void { - if (stationTemplate?.Evses == null && this.evses.size === 0) { + if (stationTemplate.Evses == null && this.evses.size === 0) { const errorMsg = `No already defined evses and charging station information from template ${this.templateFile} with no evses configuration defined` logger.error(`${this.logPrefix()} ${errorMsg}`) throw new BaseError(errorMsg) } - if (stationTemplate?.Evses?.[0] == null) { + if (stationTemplate.Evses?.[0] == null) { logger.warn( `${this.logPrefix()} Charging station information from template ${ this.templateFile } with no evse id 0 configuration` ) } - if (stationTemplate?.Evses?.[0]?.Connectors?.[0] == null) { + if (stationTemplate.Evses?.[0]?.Connectors[0] == null) { logger.warn( `${this.logPrefix()} Charging station information from template ${ this.templateFile } with evse id 0 with no connector id 0 configuration` ) } - if (Object.keys(stationTemplate?.Evses?.[0]?.Connectors as object).length > 1) { + if (Object.keys(stationTemplate.Evses?.[0]?.Connectors as object).length > 1) { logger.warn( `${this.logPrefix()} Charging station information from template ${ this.templateFile } with evse id 0 with more than one connector configuration, only connector id 0 configuration will be used` ) } - if (stationTemplate?.Evses != null) { + if (stationTemplate.Evses != null) { const evsesConfigHash = createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(stationTemplate?.Evses)) + .update(JSON.stringify(stationTemplate.Evses)) .digest('hex') const evsesConfigChanged = - this.evses?.size !== 0 && this.evsesConfigurationHash !== evsesConfigHash - if (this.evses?.size === 0 || evsesConfigChanged) { + this.evses.size !== 0 && this.evsesConfigurationHash !== evsesConfigHash + if (this.evses.size === 0 || evsesConfigChanged) { evsesConfigChanged && this.evses.clear() this.evsesConfigurationHash = evsesConfigHash - const templateMaxEvses = getMaxNumberOfEvses(stationTemplate?.Evses) + const templateMaxEvses = getMaxNumberOfEvses(stationTemplate.Evses) if (templateMaxEvses > 0) { for (const evseKey in stationTemplate.Evses) { const evseId = convertToInt(evseKey) this.evses.set(evseId, { connectors: buildConnectorsMap( - stationTemplate?.Evses[evseKey]?.Connectors, + stationTemplate.Evses[evseKey].Connectors, this.logPrefix(), this.templateFile ), @@ -1650,15 +1645,12 @@ export class ChargingStation extends EventEmitter { if (!existsSync(dirname(this.configurationFile))) { mkdirSync(dirname(this.configurationFile), { recursive: true }) } + const configurationFromFile = this.getConfigurationFromFile() let configurationData: ChargingStationConfiguration = - this.getConfigurationFromFile() != null - ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - cloneObject(this.getConfigurationFromFile()!) + configurationFromFile != null + ? cloneObject(configurationFromFile) : {} - if ( - this.stationInfo?.stationInfoPersistentConfiguration === true && - this.stationInfo != null - ) { + if (this.stationInfo?.stationInfoPersistentConfiguration === true) { configurationData.stationInfo = this.stationInfo } else { delete configurationData.stationInfo @@ -1667,7 +1659,7 @@ export class ChargingStation extends EventEmitter { this.stationInfo?.ocppPersistentConfiguration === true && Array.isArray(this.ocppConfiguration?.configurationKey) ) { - configurationData.configurationKey = this.ocppConfiguration?.configurationKey + configurationData.configurationKey = this.ocppConfiguration.configurationKey } else { delete configurationData.configurationKey } @@ -1719,7 +1711,7 @@ export class ChargingStation extends EventEmitter { this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash) this.sharedLRUCache.setChargingStationConfiguration(configurationData) this.configurationFileHash = configurationHash - }).catch((error) => { + }).catch(error => { handleFileException( this.configurationFile, FileType.ChargingStationConfiguration, @@ -1785,10 +1777,15 @@ export class ChargingStation extends EventEmitter { >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, { skipBufferingOnError: true }) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.bootNotificationResponse.currentTime = convertToDate( + this.bootNotificationResponse.currentTime + )! if (!this.isRegistered()) { this.stationInfo?.registrationMaxRetries !== -1 && ++registrationRetryCount await sleep( - this?.bootNotificationResponse?.interval != null + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + this.bootNotificationResponse?.interval != null ? secondsToMilliseconds(this.bootNotificationResponse.interval) : Constants.DEFAULT_BOOT_NOTIFICATION_INTERVAL ) @@ -1796,7 +1793,7 @@ export class ChargingStation extends EventEmitter { } while ( !this.isRegistered() && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (registrationRetryCount <= this.stationInfo.registrationMaxRetries! || + (registrationRetryCount <= this.stationInfo!.registrationMaxRetries! || this.stationInfo?.registrationMaxRetries === -1) ) } @@ -1807,8 +1804,9 @@ export class ChargingStation extends EventEmitter { } } else { logger.error( - `${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${this - .stationInfo?.registrationMaxRetries})` + `${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${ + this.stationInfo?.registrationMaxRetries + })` ) } this.autoReconnectRetryCount = 0 @@ -1898,9 +1896,9 @@ export class ChargingStation extends EventEmitter { messageId )! logger.debug( - `${this.logPrefix()} << Command '${ - requestCommandName ?? Constants.UNKNOWN_COMMAND - }' received response payload: ${JSON.stringify(response)}` + `${this.logPrefix()} << Command '${requestCommandName}' received response payload: ${JSON.stringify( + response + )}` ) responseCallback(commandPayload, requestPayload) } @@ -1919,9 +1917,9 @@ export class ChargingStation extends EventEmitter { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const [, errorCallback, requestCommandName] = this.getCachedRequest(messageType, messageId)! logger.debug( - `${this.logPrefix()} << Command '${ - requestCommandName ?? Constants.UNKNOWN_COMMAND - }' received error response payload: ${JSON.stringify(errorResponse)}` + `${this.logPrefix()} << Command '${requestCommandName}' received error response payload: ${JSON.stringify( + errorResponse + )}` ) errorCallback(new OCPPError(errorType, errorMessage, requestCommandName, errorDetails)) } @@ -2027,19 +2025,24 @@ export class ChargingStation extends EventEmitter { logger.error(`${this.logPrefix()} WebSocket error:`, error) } - private getEnergyActiveImportRegister (connectorStatus: ConnectorStatus, rounded = false): number { + private getEnergyActiveImportRegister ( + connectorStatus: ConnectorStatus | undefined, + rounded = false + ): number { if (this.stationInfo?.meteringPerTransaction === true) { return ( (rounded - ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue!) + ? connectorStatus?.transactionEnergyActiveImportRegisterValue != null + ? Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue) + : undefined : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0 ) } return ( (rounded - ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - Math.round(connectorStatus.energyActiveImportRegisterValue!) + ? connectorStatus?.energyActiveImportRegisterValue != null + ? Math.round(connectorStatus.energyActiveImportRegisterValue) + : undefined : connectorStatus?.energyActiveImportRegisterValue) ?? 0 ) } @@ -2073,8 +2076,7 @@ export class ChargingStation extends EventEmitter { private getConnectionTimeout (): number { if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) != null) { return convertToInt( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value! ?? + getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)?.value ?? Constants.DEFAULT_CONNECTION_TIMEOUT ) } @@ -2091,7 +2093,7 @@ export class ChargingStation extends EventEmitter { private getMaximumAmperage (stationInfo?: ChargingStationInfo): number | undefined { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const maximumPower = (stationInfo ?? this.stationInfo).maximumPower! + const maximumPower = (stationInfo ?? this.stationInfo!).maximumPower! switch (this.getCurrentOutType(stationInfo)) { case CurrentType.AC: return ACElectricUtils.amperagePerPhaseFromPower( @@ -2105,12 +2107,14 @@ export class ChargingStation extends EventEmitter { } private getCurrentOutType (stationInfo?: ChargingStationInfo): CurrentType { - return (stationInfo ?? this.stationInfo).currentOutType ?? CurrentType.AC + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return (stationInfo ?? this.stationInfo!).currentOutType ?? CurrentType.AC } private getVoltageOut (stationInfo?: ChargingStationInfo): Voltage { return ( - (stationInfo ?? this.stationInfo).voltageOut ?? + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + (stationInfo ?? this.stationInfo!).voltageOut ?? getDefaultVoltageOut(this.getCurrentOutType(stationInfo), this.logPrefix(), this.templateFile) ) } @@ -2119,13 +2123,14 @@ export class ChargingStation extends EventEmitter { if ( isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) != null + getConfigurationKey(this, this.stationInfo!.amperageLimitationOcppKey!) != null ) { return ( convertToInt( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)?.value - ) / getAmperageLimitationUnitDivider(this.stationInfo) + getConfigurationKey(this, this.stationInfo!.amperageLimitationOcppKey!)!.value + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + ) / getAmperageLimitationUnitDivider(this.stationInfo!) ) } } @@ -2166,7 +2171,7 @@ export class ChargingStation extends EventEmitter { } } } - if (this.stationInfo.firmwareStatus === FirmwareStatus.Installing) { + if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) { await this.ocppRequestService.requestHandler< FirmwareStatusNotificationRequest, FirmwareStatusNotificationResponse @@ -2177,7 +2182,7 @@ export class ChargingStation extends EventEmitter { } // Start the ATG - if (this.getAutomaticTransactionGeneratorConfiguration().enable) { + if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { this.startAutomaticTransactionGenerator() } this.flushMessageBuffer() @@ -2214,7 +2219,7 @@ export class ChargingStation extends EventEmitter { evseId ) ) - delete connectorStatus?.status + delete connectorStatus.status } } } @@ -2236,7 +2241,7 @@ export class ChargingStation extends EventEmitter { } private startWebSocketPing (): void { - const webSocketPingInterval: number = + const webSocketPingInterval = getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) != null ? convertToInt( getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value @@ -2309,7 +2314,7 @@ export class ChargingStation extends EventEmitter { } const errorMsg = 'No supervision url(s) configured' logger.error(`${this.logPrefix()} ${errorMsg}`) - throw new BaseError(`${errorMsg}`) + throw new BaseError(errorMsg) } private stopHeartbeat (): void { @@ -2332,12 +2337,12 @@ export class ChargingStation extends EventEmitter { // Stop heartbeat this.stopHeartbeat() // Stop the ATG if needed - if (this.getAutomaticTransactionGeneratorConfiguration().stopOnConnectionFailure) { + if (this.getAutomaticTransactionGeneratorConfiguration()?.stopOnConnectionFailure === true) { this.stopAutomaticTransactionGenerator() } if ( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.autoReconnectRetryCount < this.stationInfo.autoReconnectMaxRetries! || + this.autoReconnectRetryCount < this.stationInfo!.autoReconnectMaxRetries! || this.stationInfo?.autoReconnectMaxRetries === -1 ) { ++this.autoReconnectRetryCount @@ -2347,9 +2352,7 @@ export class ChargingStation extends EventEmitter { : secondsToMilliseconds(this.getConnectionTimeout()) const reconnectDelayWithdraw = 1000 const reconnectTimeout = - reconnectDelay != null && reconnectDelay - reconnectDelayWithdraw > 0 - ? reconnectDelay - reconnectDelayWithdraw - : 0 + reconnectDelay - reconnectDelayWithdraw > 0 ? reconnectDelay - reconnectDelayWithdraw : 0 logger.error( `${this.logPrefix()} WebSocket connection retry in ${roundTo( reconnectDelay,