refactor: switch eslint configuration to strict type checking
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 4 Jan 2024 11:16:07 +0000 (12:16 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 4 Jan 2024 11:16:07 +0000 (12:16 +0100)
recommended rules

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
40 files changed:
.eslintrc.cjs
bundle.js
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/ConfigurationKeyUtils.ts
src/charging-station/Helpers.ts
src/charging-station/IdTagsCache.ts
src/charging-station/SharedLRUCache.ts
src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20RequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/performance/PerformanceStatistics.ts
src/performance/storage/JsonFileStorage.ts
src/performance/storage/MikroOrmStorage.ts
src/performance/storage/MongoDBStorage.ts
src/performance/storage/Storage.ts
src/types/WorkerBroadcastChannel.ts
src/utils/Configuration.ts
src/utils/ErrorUtils.ts
src/utils/MessageChannelUtils.ts
src/utils/StatisticUtils.ts
src/utils/Utils.ts
src/worker/WorkerAbstract.ts
src/worker/WorkerDynamicPool.ts
src/worker/WorkerFixedPool.ts
src/worker/WorkerSet.ts

index 659ebd9934a91d326634c40a2c7a0ebc9eb6e8e5..a9d87cf38fbbbd3101d27bc02910f1767b7898fc 100644 (file)
@@ -61,7 +61,7 @@ module.exports = defineConfig({
       },
       plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc'],
       extends: [
-        'plugin:@typescript-eslint/recommended-type-checked',
+        'plugin:@typescript-eslint/strict-type-checked',
         'plugin:@typescript-eslint/stylistic-type-checked',
         'plugin:import/typescript',
         'standard-with-typescript'
index 455da66fae8497ea74113c1d3813ae34441c765a..5543d9cbe5adc89dd396c670b454f5442bd4ada7 100644 (file)
--- a/bundle.js
+++ b/bundle.js
@@ -5,7 +5,6 @@ import chalk from 'chalk'
 import { build } from 'esbuild'
 import { clean } from 'esbuild-plugin-clean'
 import { copy } from 'esbuild-plugin-copy'
-
 ;(async () => {
   const isDevelopmentBuild = env.BUILD === 'development'
   const sourcemap = !!isDevelopmentBuild
index 94198ac6f502d7433f7c5b0498c476ec328b52ff..38efbf51a22ce5c19390a0219702ddb81c9dfd2c 100644 (file)
@@ -52,13 +52,16 @@ export class AutomaticTransactionGenerator {
   public static getInstance (
     chargingStation: ChargingStation
   ): AutomaticTransactionGenerator | undefined {
-    if (!AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId)) {
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    if (!AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo!.hashId)) {
       AutomaticTransactionGenerator.instances.set(
-        chargingStation.stationInfo.hashId,
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        chargingStation.stationInfo!.hashId,
         new AutomaticTransactionGenerator(chargingStation)
       )
     }
-    return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo.hashId)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo!.hashId)
   }
 
   public start (): void {
@@ -124,7 +127,7 @@ export class AutomaticTransactionGenerator {
 
   private startConnectors (): void {
     if (
-      this.connectorsStatus?.size > 0 &&
+      this.connectorsStatus.size > 0 &&
       this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()
     ) {
       this.connectorsStatus.clear()
@@ -178,7 +181,6 @@ export class AutomaticTransactionGenerator {
       )}`
     )
     while (this.connectorsStatus.get(connectorId)?.start === true) {
-      await this.waitChargingStationServiceInitialization(connectorId)
       await this.waitChargingStationAvailable(connectorId)
       await this.waitConnectorAvailable(connectorId)
       if (!this.canStartConnector(connectorId)) {
@@ -188,9 +190,9 @@ export class AutomaticTransactionGenerator {
       const wait = secondsToMilliseconds(
         getRandomInteger(
           this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
-            .maxDelayBetweenTwoTransactions,
+            ?.maxDelayBetweenTwoTransactions,
           this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
-            .minDelayBetweenTwoTransactions
+            ?.minDelayBetweenTwoTransactions
         )
       )
       logger.info(`${this.logPrefix(connectorId)} waiting for ${formatDurationMilliSeconds(wait)}`)
@@ -198,18 +200,19 @@ export class AutomaticTransactionGenerator {
       const start = secureRandom()
       if (
         start <
-        this.chargingStation.getAutomaticTransactionGeneratorConfiguration().probabilityOfStart
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.probabilityOfStart
       ) {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0
         // Start transaction
         const startResponse = await this.startTransaction(connectorId)
-        if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
+        if (startResponse?.idTagInfo.status === AuthorizationStatus.ACCEPTED) {
           // Wait until end of transaction
           const waitTrxEnd = secondsToMilliseconds(
             getRandomInteger(
-              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration,
-              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration
+              this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.maxDuration,
+              this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.minDuration
             )
           )
           logger.info(
@@ -272,7 +275,8 @@ export class AutomaticTransactionGenerator {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
         hoursToMilliseconds(
-          this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.stopAfterHours
         ) -
         previousRunDuration
     )
@@ -312,21 +316,6 @@ export class AutomaticTransactionGenerator {
     return true
   }
 
-  private async waitChargingStationServiceInitialization (connectorId: number): Promise<void> {
-    let logged = false
-    while (this.chargingStation?.ocppRequestService == null) {
-      if (!logged) {
-        logger.info(
-          `${this.logPrefix(
-            connectorId
-          )} transaction loop waiting for charging station service to be initialized`
-        )
-        logged = true
-      }
-      await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME)
-    }
-  }
-
   private async waitChargingStationAvailable (connectorId: number): Promise<void> {
     let logged = false
     while (!this.chargingStation.isChargingStationAvailable()) {
@@ -406,14 +395,14 @@ export class AutomaticTransactionGenerator {
     if (connectorStatus == null) {
       return
     }
-    delete connectorStatus?.startDate
-    delete connectorStatus?.lastRunDate
-    delete connectorStatus?.stopDate
-    delete connectorStatus?.stoppedDate
+    delete connectorStatus.startDate
+    delete connectorStatus.lastRunDate
+    delete connectorStatus.stopDate
+    delete connectorStatus.stoppedDate
     if (
       !this.started &&
       (connectorStatus.start ||
-        !this.chargingStation.getAutomaticTransactionGeneratorConfiguration().enable)
+        this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.enable !== true)
     ) {
       connectorStatus.start = false
     }
@@ -428,7 +417,7 @@ export class AutomaticTransactionGenerator {
     if (this.chargingStation.hasIdTags()) {
       const idTag = IdTagsCache.getInstance().getIdTag(
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.chargingStation.getAutomaticTransactionGeneratorConfiguration().idTagDistribution!,
+        this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.idTagDistribution!,
         this.chargingStation,
         connectorId
       )
@@ -499,7 +488,7 @@ export class AutomaticTransactionGenerator {
       stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason)
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       ++this.connectorsStatus.get(connectorId)!.stopTransactionRequests!
-      if (stopResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
+      if (stopResponse.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         ++this.connectorsStatus.get(connectorId)!.acceptedStopTransactionRequests!
       } else {
@@ -526,7 +515,7 @@ export class AutomaticTransactionGenerator {
 
   private readonly logPrefix = (connectorId?: number): string => {
     return logPrefix(
-      ` ${this.chargingStation.stationInfo.chargingStationId} | ATG${
+      ` ${this.chargingStation.stationInfo?.chargingStationId} | ATG${
         connectorId != null ? ` on connector #${connectorId}` : ''
       }:`
     )
@@ -538,7 +527,7 @@ export class AutomaticTransactionGenerator {
   ): void {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     ++this.connectorsStatus.get(connectorId)!.startTransactionRequests!
-    if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
+    if (startResponse.idTagInfo.status === AuthorizationStatus.ACCEPTED) {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       ++this.connectorsStatus.get(connectorId)!.acceptedStartTransactionRequests!
     } else {
index 5b23676f24e39049cedf24f7581132f5b265a925..3993437be907c934cd1e937d39ffe532dd3bab27 100644 (file)
@@ -129,7 +129,7 @@ export class Bootstrap extends EventEmitter {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
           try {
-            const nbStations = stationTemplateUrl.numberOfStations ?? 0
+            const nbStations = stationTemplateUrl.numberOfStations
             for (let index = 1; index <= nbStations; index++) {
               await this.startChargingStation(index, stationTemplateUrl)
             }
@@ -156,7 +156,7 @@ export class Bootstrap extends EventEmitter {
                 : ''
             } worker(s) concurrently running in '${workerConfiguration.processType}' mode${
               this.workerImplementation?.maxElementsPerWorker != null
-                ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)`
+                ? ` (${this.workerImplementation.maxElementsPerWorker} charging station(s) per worker)`
                 : ''
             }`
           )
@@ -246,7 +246,7 @@ export class Bootstrap extends EventEmitter {
 
   private initializeWorkerImplementation (workerConfiguration: WorkerConfiguration): void {
     let elementsPerWorker: number | undefined
-    switch (workerConfiguration?.elementsPerWorker) {
+    switch (workerConfiguration.elementsPerWorker) {
       case 'auto':
         elementsPerWorker =
           this.numberOfChargingStations > availableParallelism()
@@ -373,7 +373,7 @@ export class Bootstrap extends EventEmitter {
       if (isNotEmptyArray(stationTemplateUrls)) {
         this.numberOfChargingStationTemplates = stationTemplateUrls.length
         for (const stationTemplateUrl of stationTemplateUrls) {
-          this.numberOfChargingStations += stationTemplateUrl.numberOfStations ?? 0
+          this.numberOfChargingStations += stationTemplateUrl.numberOfStations
         }
       } else {
         console.warn(
@@ -413,7 +413,7 @@ export class Bootstrap extends EventEmitter {
   private gracefulShutdown (): void {
     this.stop()
       .then(() => {
-        console.info(`${chalk.green('Graceful shutdown')}`)
+        console.info(chalk.green('Graceful shutdown'))
         this.uiServer?.stop()
         // stop() asks for charging stations to stop by default
         this.waitChargingStationsStopped()
index 7c4b098d3de215a7781d0909572b55e665518013..6513f68b19e3d8397bb999bd5f7bf0c661e8f311 100644 (file)
@@ -156,7 +156,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,7 +171,7 @@ export class ChargingStation extends EventEmitter {
   public ocppRequestService!: OCPPRequestService
   public bootNotificationRequest!: BootNotificationRequest
   public bootNotificationResponse!: BootNotificationResponse | undefined
-  public powerDivider!: number
+  public powerDivider?: number
   private stopping: boolean
   private configurationFile!: string
   private configurationFileHash!: string
@@ -227,19 +227,19 @@ 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 (isNotEmptyString(this.stationInfo?.chargingStationId)) {
+      return logPrefix(` ${this.stationInfo?.chargingStationId} |`)
     }
     let stationTemplate: ChargingStationTemplate | undefined
     try {
@@ -254,11 +254,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: ChargingStationInfo = stationInfo ?? this.stationInfo!
     switch (this.getCurrentOutType(stationInfo)) {
       case CurrentType.AC:
         return localStationInfo.numberOfPhases ?? 3
@@ -268,23 +269,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 this?.bootNotificationResponse?.status == null
+    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 {
@@ -348,7 +349,7 @@ export class ChargingStation extends EventEmitter {
     if (
       this.getAmperageLimitation() != null &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.getAmperageLimitation()! < this.stationInfo.maximumAmperage!
+      this.getAmperageLimitation()! < this.stationInfo!.maximumAmperage!
     ) {
       connectorAmperageLimitationPowerLimit =
         (this.stationInfo?.currentOutType === CurrentType.AC
@@ -361,11 +362,12 @@ export class ChargingStation extends EventEmitter {
                 (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!, this.getAmperageLimitation()!)) /
+        // 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(
@@ -494,12 +496,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()
     }
@@ -643,11 +646,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) {
@@ -704,7 +707,7 @@ export class ChargingStation extends EventEmitter {
   public async reset (reason?: StopTransactionReason): Promise<void> {
     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()
   }
@@ -733,13 +736,13 @@ export class ChargingStation extends EventEmitter {
     if (!checkChargingStation(this, this.logPrefix())) {
       return
     }
-    if (this.stationInfo.supervisionUser != null && this.stationInfo.supervisionPassword != null) {
+    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()
     }
 
@@ -790,7 +793,9 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  public getAutomaticTransactionGeneratorConfiguration (): AutomaticTransactionGeneratorConfiguration {
+  public getAutomaticTransactionGeneratorConfiguration ():
+  | AutomaticTransactionGeneratorConfiguration
+  | undefined {
     if (this.automaticTransactionGeneratorConfiguration == null) {
       let automaticTransactionGeneratorConfiguration:
       | AutomaticTransactionGeneratorConfiguration
@@ -803,7 +808,7 @@ export class ChargingStation extends EventEmitter {
         stationConfiguration?.automaticTransactionGenerator != null
       ) {
         automaticTransactionGeneratorConfiguration =
-          stationConfiguration?.automaticTransactionGenerator
+          stationConfiguration.automaticTransactionGenerator
       } else {
         automaticTransactionGeneratorConfiguration = stationTemplate?.AutomaticTransactionGenerator
       }
@@ -853,8 +858,8 @@ 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,
@@ -942,14 +947,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
         }
       }
@@ -1088,32 +1093,32 @@ export class ChargingStation extends EventEmitter {
     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)
     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
@@ -1132,10 +1137,10 @@ export class ChargingStation extends EventEmitter {
         },
         reset: true
       },
-      stationTemplate?.firmwareUpgrade ?? {}
+      stationTemplate.firmwareUpgrade ?? {}
     )
     stationInfo.resetTime =
-      stationTemplate?.resetTime != null
+      stationTemplate.resetTime != null
         ? secondsToMilliseconds(stationTemplate.resetTime)
         : Constants.CHARGING_STATION_DEFAULT_RESET_TIME
     return stationInfo
@@ -1148,7 +1153,7 @@ export class ChargingStation extends EventEmitter {
     if (stationInfoPersistentConfiguration) {
       stationInfo = this.getConfigurationFromFile()?.stationInfo
       if (stationInfo != null) {
-        delete stationInfo?.infoHash
+        delete stationInfo.infoHash
       }
     }
     return stationInfo
@@ -1158,7 +1163,7 @@ export class ChargingStation extends EventEmitter {
     const defaultStationInfo = Constants.DEFAULT_STATION_INFO
     const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate()
     const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile(
-      stationInfoFromTemplate?.stationInfoPersistentConfiguration
+      stationInfoFromTemplate.stationInfoPersistentConfiguration
     )
     // Priority:
     // 1. charging station info from template
@@ -1169,8 +1174,7 @@ export class ChargingStation extends EventEmitter {
     }
     stationInfoFromFile != null &&
       propagateSerialNumber(
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.getTemplateFromFile()!,
+        this.getTemplateFromFile(),
         stationInfoFromFile,
         stationInfoFromTemplate
       )
@@ -1199,7 +1203,7 @@ export class ChargingStation extends EventEmitter {
     )
     const stationConfiguration = this.getConfigurationFromFile()
     if (
-      stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash &&
+      stationConfiguration?.stationInfo?.templateHash === stationTemplate.templateHash &&
       (stationConfiguration?.connectorsStatus != null || stationConfiguration?.evsesStatus != null)
     ) {
       checkConfiguration(stationConfiguration, this.logPrefix(), this.configurationFile)
@@ -1234,7 +1238,7 @@ export class ChargingStation extends EventEmitter {
     }
     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
@@ -1253,7 +1257,7 @@ export class ChargingStation extends EventEmitter {
         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()),
@@ -1295,7 +1299,7 @@ export class ChargingStation extends EventEmitter {
     }
     if (
       this.stationInfo?.supervisionUrlOcppConfiguration === true &&
-      isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
+      isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) == null
     ) {
@@ -1308,7 +1312,7 @@ 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
       getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) != null
     ) {
@@ -1318,15 +1322,15 @@ 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
     ) {
       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 (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) {
@@ -1395,11 +1399,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>(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>(evseStatusConfiguration)
         delete evseStatus.connectorsStatus
@@ -1414,7 +1418,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)
@@ -1426,11 +1430,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)
@@ -1442,45 +1446,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,
@@ -1509,48 +1514,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
               ),
@@ -1633,10 +1638,7 @@ export class ChargingStation extends EventEmitter {
             ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
             cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()!)
             : {}
-        if (
-          this.stationInfo?.stationInfoPersistentConfiguration === true &&
-          this.stationInfo != null
-        ) {
+        if (this.stationInfo?.stationInfoPersistentConfiguration === true) {
           configurationData.stationInfo = this.stationInfo
         } else {
           delete configurationData.stationInfo
@@ -1645,7 +1647,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
         }
@@ -1766,7 +1768,8 @@ export class ChargingStation extends EventEmitter {
           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
             )
@@ -1774,7 +1777,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)
         )
       }
@@ -1876,9 +1879,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)
   }
@@ -1897,9 +1900,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))
   }
@@ -2011,14 +2014,14 @@ export class ChargingStation extends EventEmitter {
         (rounded
           ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           Math.round(connectorStatus.transactionEnergyActiveImportRegisterValue!)
-          : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0
+          : connectorStatus.transactionEnergyActiveImportRegisterValue) ?? 0
       )
     }
     return (
       (rounded
         ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         Math.round(connectorStatus.energyActiveImportRegisterValue!)
-        : connectorStatus?.energyActiveImportRegisterValue) ?? 0
+        : connectorStatus.energyActiveImportRegisterValue) ?? 0
     )
   }
 
@@ -2051,8 +2054,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
       )
     }
@@ -2069,7 +2071,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(
@@ -2083,12 +2085,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)
     )
   }
@@ -2097,13 +2101,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!)
       )
     }
   }
@@ -2144,7 +2149,7 @@ export class ChargingStation extends EventEmitter {
         }
       }
     }
-    if (this.stationInfo.firmwareStatus === FirmwareStatus.Installing) {
+    if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) {
       await this.ocppRequestService.requestHandler<
       FirmwareStatusNotificationRequest,
       FirmwareStatusNotificationResponse
@@ -2155,7 +2160,7 @@ export class ChargingStation extends EventEmitter {
     }
 
     // Start the ATG
-    if (this.getAutomaticTransactionGeneratorConfiguration().enable) {
+    if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
       this.startAutomaticTransactionGenerator()
     }
     this.flushMessageBuffer()
@@ -2192,7 +2197,7 @@ export class ChargingStation extends EventEmitter {
                 evseId
               )
             )
-            delete connectorStatus?.status
+            delete connectorStatus.status
           }
         }
       }
@@ -2287,7 +2292,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 {
@@ -2310,12 +2315,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
@@ -2325,9 +2330,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,
index 556cf54a57745f8563c9b9373729e79ecd976908..bb0d9978cc7d110330b271ca685160fcdf2ecd1a 100644 (file)
@@ -46,7 +46,7 @@ export const addConfigurationKey = (
   }
   params = { ...{ overwrite: false, save: false }, ...params }
   let keyFound = getConfigurationKey(chargingStation, key)
-  if (keyFound != null && params?.overwrite === true) {
+  if (keyFound != null && params.overwrite === true) {
     deleteConfigurationKey(chargingStation, keyFound.key, {
       save: false
     })
@@ -61,7 +61,7 @@ export const addConfigurationKey = (
       visible: options.visible,
       reboot: options.reboot
     })
-    params?.save === true && chargingStation.saveOcppConfiguration()
+    params.save === true && chargingStation.saveOcppConfiguration()
   } else {
     logger.error(
       `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`,
@@ -99,13 +99,13 @@ export const deleteConfigurationKey = (
   params?: DeleteConfigurationKeyParams
 ): ConfigurationKey[] | undefined => {
   params = { ...{ save: true, caseInsensitive: false }, ...params }
-  const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive)
+  const keyFound = getConfigurationKey(chargingStation, key, params.caseInsensitive)
   if (keyFound != null) {
     const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice(
       chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound),
       1
     )
-    params?.save === true && chargingStation.saveOcppConfiguration()
+    params.save === true && chargingStation.saveOcppConfiguration()
     return deletedConfigurationKey
   }
 }
index a97a9f5ad2ecfd14b4ac4a7f934b7c8d63f60715..9a5eeb6ea97822f9946d36b672ea82bc1770d51b 100644 (file)
@@ -81,9 +81,9 @@ export const getChargingStationId = (
   }
   // In case of multiple instances: add instance index to charging station id
   const instanceIndex = env.CF_INSTANCE_INDEX ?? 0
-  const idSuffix = stationTemplate?.nameSuffix ?? ''
+  const idSuffix = stationTemplate.nameSuffix ?? ''
   const idStr = `000000000${index.toString()}`
-  return stationTemplate?.fixedName === true
+  return stationTemplate.fixedName === true
     ? stationTemplate.baseName
     : `${stationTemplate.baseName}-${instanceIndex.toString()}${idStr.substring(
         idStr.length - 4
@@ -191,14 +191,16 @@ export const getPhaseRotationValue = (
   }
 }
 
-export const getMaxNumberOfEvses = (evses: Record<string, EvseTemplate>): number => {
+export const getMaxNumberOfEvses = (evses: Record<string, EvseTemplate> | undefined): number => {
   if (evses == null) {
     return -1
   }
   return Object.keys(evses).length
 }
 
-const getMaxNumberOfConnectors = (connectors: Record<string, ConnectorStatus>): number => {
+const getMaxNumberOfConnectors = (
+  connectors: Record<string, ConnectorStatus> | undefined
+): number => {
   if (connectors == null) {
     return -1
   }
@@ -212,17 +214,17 @@ export const getBootConnectorStatus = (
 ): ConnectorStatusEnum => {
   let connectorBootStatus: ConnectorStatusEnum
   if (
-    connectorStatus?.status == null &&
+    connectorStatus.status == null &&
     (!chargingStation.isChargingStationAvailable() ||
       !chargingStation.isConnectorAvailable(connectorId))
   ) {
     connectorBootStatus = ConnectorStatusEnum.Unavailable
-  } else if (connectorStatus?.status == null && connectorStatus?.bootStatus != null) {
+  } else if (connectorStatus.status == null && connectorStatus.bootStatus != null) {
     // Set boot status in template at startup
-    connectorBootStatus = connectorStatus?.bootStatus
-  } else if (connectorStatus?.status != null) {
+    connectorBootStatus = connectorStatus.bootStatus
+  } else if (connectorStatus.status != null) {
     // Set previous status at startup
-    connectorBootStatus = connectorStatus?.status
+    connectorBootStatus = connectorStatus.status
   } else {
     // Set default status
     connectorBootStatus = ConnectorStatusEnum.Available
@@ -231,7 +233,7 @@ export const getBootConnectorStatus = (
 }
 
 export const checkTemplate = (
-  stationTemplate: ChargingStationTemplate,
+  stationTemplate: ChargingStationTemplate | undefined,
   logPrefix: string,
   templateFile: string
 ): void => {
@@ -288,14 +290,13 @@ export const checkConnectorsConfiguration = (
 } => {
   const configuredMaxConnectors = getConfiguredMaxNumberOfConnectors(stationTemplate)
   checkConfiguredMaxConnectors(configuredMaxConnectors, logPrefix, templateFile)
-  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-  const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors!)
+  const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors)
   checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile)
   const templateMaxAvailableConnectors =
     stationTemplate.Connectors?.[0] != null ? templateMaxConnectors - 1 : templateMaxConnectors
   if (
     configuredMaxConnectors > templateMaxAvailableConnectors &&
-    stationTemplate?.randomConnectors !== true
+    stationTemplate.randomConnectors !== true
   ) {
     logger.warn(
       `${logPrefix} Number of connectors exceeds the number of connector configurations in template ${templateFile}, forcing random connector configurations affectation`
@@ -311,7 +312,7 @@ export const checkStationInfoConnectorStatus = (
   logPrefix: string,
   templateFile: string
 ): void => {
-  if (connectorStatus?.status != null) {
+  if (connectorStatus.status != null) {
     logger.warn(
       `${logPrefix} Charging station information from template ${templateFile} with connector id ${connectorId} status configuration defined, undefine it`
     )
@@ -377,13 +378,13 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus): void =>
   connectorStatus.idTagAuthorized = false
   connectorStatus.transactionRemoteStarted = false
   connectorStatus.transactionStarted = false
-  delete connectorStatus?.transactionStart
-  delete connectorStatus?.transactionId
-  delete connectorStatus?.localAuthorizeIdTag
-  delete connectorStatus?.authorizeIdTag
-  delete connectorStatus?.transactionIdTag
+  delete connectorStatus.transactionStart
+  delete connectorStatus.transactionId
+  delete connectorStatus.localAuthorizeIdTag
+  delete connectorStatus.authorizeIdTag
+  delete connectorStatus.transactionIdTag
   connectorStatus.transactionEnergyActiveImportRegisterValue = 0
-  delete connectorStatus?.transactionBeginMeterValue
+  delete connectorStatus.transactionBeginMeterValue
 }
 
 export const createBootNotificationRequest = (
@@ -488,22 +489,22 @@ export const createSerialNumber = (
 ): void => {
   params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params }
   const serialNumberSuffix =
-    params?.randomSerialNumber === true
+    params.randomSerialNumber === true
       ? getRandomSerialNumberSuffix({
         upperCase: params.randomSerialNumberUpperCase
       })
       : ''
-  isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) &&
+  isNotEmptyString(stationTemplate.chargePointSerialNumberPrefix) &&
     (stationInfo.chargePointSerialNumber = `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`)
-  isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) &&
+  isNotEmptyString(stationTemplate.chargeBoxSerialNumberPrefix) &&
     (stationInfo.chargeBoxSerialNumber = `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`)
-  isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) &&
+  isNotEmptyString(stationTemplate.meterSerialNumberPrefix) &&
     (stationInfo.meterSerialNumber = `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`)
 }
 
 export const propagateSerialNumber = (
-  stationTemplate: ChargingStationTemplate,
-  stationInfoSrc: ChargingStationInfo,
+  stationTemplate: ChargingStationTemplate | undefined,
+  stationInfoSrc: ChargingStationInfo | undefined,
   stationInfoDst: ChargingStationInfo
 ): void => {
   if (stationInfoSrc == null || stationTemplate == null) {
@@ -511,18 +512,18 @@ export const propagateSerialNumber = (
       'Missing charging station template or existing configuration to propagate serial number'
     )
   }
-  stationTemplate?.chargePointSerialNumberPrefix != null &&
-  stationInfoSrc?.chargePointSerialNumber != null
+  stationTemplate.chargePointSerialNumberPrefix != null &&
+  stationInfoSrc.chargePointSerialNumber != null
     ? (stationInfoDst.chargePointSerialNumber = stationInfoSrc.chargePointSerialNumber)
-    : stationInfoDst?.chargePointSerialNumber != null &&
+    : stationInfoDst.chargePointSerialNumber != null &&
       delete stationInfoDst.chargePointSerialNumber
-  stationTemplate?.chargeBoxSerialNumberPrefix != null &&
-  stationInfoSrc?.chargeBoxSerialNumber != null
+  stationTemplate.chargeBoxSerialNumberPrefix != null &&
+  stationInfoSrc.chargeBoxSerialNumber != null
     ? (stationInfoDst.chargeBoxSerialNumber = stationInfoSrc.chargeBoxSerialNumber)
-    : stationInfoDst?.chargeBoxSerialNumber != null && delete stationInfoDst.chargeBoxSerialNumber
-  stationTemplate?.meterSerialNumberPrefix != null && stationInfoSrc?.meterSerialNumber != null
+    : stationInfoDst.chargeBoxSerialNumber != null && delete stationInfoDst.chargeBoxSerialNumber
+  stationTemplate.meterSerialNumberPrefix != null && stationInfoSrc.meterSerialNumber != null
     ? (stationInfoDst.meterSerialNumber = stationInfoSrc.meterSerialNumber)
-    : stationInfoDst?.meterSerialNumber != null && delete stationInfoDst.meterSerialNumber
+    : stationInfoDst.meterSerialNumber != null && delete stationInfoDst.meterSerialNumber
 }
 
 export const hasFeatureProfile = (
@@ -589,12 +590,12 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = (
       chargingStation.logPrefix()
     )
     if (result != null) {
-      limit = result?.limit
-      chargingProfile = result?.chargingProfile
+      limit = result.limit
+      chargingProfile = result.chargingProfile
       switch (chargingStation.stationInfo?.currentOutType) {
         case CurrentType.AC:
           limit =
-            chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
+            chargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT
               ? limit
               : ACElectricUtils.powerTotal(
                 chargingStation.getNumberOfPhases(),
@@ -605,17 +606,19 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = (
           break
         case CurrentType.DC:
           limit =
-            chargingProfile?.chargingSchedule?.chargingRateUnit === ChargingRateUnitType.WATT
+            chargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT
               ? limit
               : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
               DCElectricUtils.power(chargingStation.stationInfo.voltageOut!, limit)
       }
       const connectorMaximumPower =
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        chargingStation.stationInfo.maximumPower! / chargingStation.powerDivider
+        chargingStation.stationInfo!.maximumPower! / chargingStation.powerDivider!
       if (limit > connectorMaximumPower) {
         logger.error(
-          `${chargingStation.logPrefix()} ${moduleName}.getChargingStationConnectorChargingProfilesPowerLimit: Charging profile id ${chargingProfile?.chargingProfileId} limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
+          `${chargingStation.logPrefix()} ${moduleName}.getChargingStationConnectorChargingProfilesPowerLimit: Charging profile id ${
+            chargingProfile.chargingProfileId
+          } limit ${limit} is greater than connector id ${connectorId} maximum ${connectorMaximumPower}: %j`,
           result
         )
         limit = connectorMaximumPower
@@ -682,7 +685,8 @@ const getConfiguredMaxNumberOfConnectors = (stationTemplate: ChargingStationTemp
     configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number
   } else if (stationTemplate.Connectors != null && stationTemplate.Evses == null) {
     configuredMaxNumberOfConnectors =
-      stationTemplate.Connectors?.[0] != null
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+      stationTemplate.Connectors[0] != null
         ? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1
         : getMaxNumberOfConnectors(stationTemplate.Connectors)
   } else if (stationTemplate.Evses != null && stationTemplate.Connectors == null) {
@@ -746,7 +750,7 @@ const warnDeprecatedTemplateKey = (
   templateFile: string,
   logMsgToAppend = ''
 ): void => {
-  if (template?.[key as keyof ChargingStationTemplate] !== undefined) {
+  if (template[key as keyof ChargingStationTemplate] !== undefined) {
     const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
       isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
     }`
@@ -760,7 +764,7 @@ const convertDeprecatedTemplateKey = (
   deprecatedKey: string,
   key?: string
 ): void => {
-  if (template?.[deprecatedKey as keyof ChargingStationTemplate] !== undefined) {
+  if (template[deprecatedKey as keyof ChargingStationTemplate] !== undefined) {
     if (key !== undefined) {
       (template as unknown as Record<string, unknown>)[key] =
         template[deprecatedKey as keyof ChargingStationTemplate]
@@ -796,21 +800,21 @@ const getLimitFromChargingProfiles = (
   const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
   for (const chargingProfile of chargingProfiles) {
     const chargingSchedule = chargingProfile.chargingSchedule
-    if (chargingSchedule?.startSchedule == null && connectorStatus?.transactionStarted === true) {
+    if (chargingSchedule.startSchedule == null && connectorStatus.transactionStarted === true) {
       logger.debug(
         `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} has no startSchedule defined. Trying to set it to the connector current transaction start date`
       )
       // OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
-      chargingSchedule.startSchedule = connectorStatus?.transactionStart
+      chargingSchedule.startSchedule = connectorStatus.transactionStart
     }
-    if (chargingSchedule?.startSchedule != null && !isDate(chargingSchedule?.startSchedule)) {
+    if (chargingSchedule.startSchedule != null && !isDate(chargingSchedule.startSchedule)) {
       logger.warn(
         `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} startSchedule property is not a Date instance. Trying to convert it to a Date instance`
       )
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      chargingSchedule.startSchedule = convertToDate(chargingSchedule?.startSchedule)!
+      chargingSchedule.startSchedule = convertToDate(chargingSchedule.startSchedule)!
     }
-    if (chargingSchedule?.startSchedule != null && chargingSchedule?.duration == null) {
+    if (chargingSchedule.startSchedule != null && chargingSchedule.duration == null) {
       logger.debug(
         `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} has no duration defined and will be set to the maximum time allowed`
       )
@@ -937,8 +941,8 @@ export const prepareChargingProfileKind = (
         )
         delete chargingProfile.chargingSchedule.startSchedule
       }
-      if (connectorStatus?.transactionStarted === true) {
-        chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart
+      if (connectorStatus.transactionStarted === true) {
+        chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
       }
       // FIXME: Handle relative charging profile duration
       break
@@ -973,19 +977,13 @@ export const canProceedChargingProfile = (
     )
     return false
   }
-  if (
-    chargingProfile.chargingSchedule.startSchedule != null &&
-    !isValidTime(chargingProfile.chargingSchedule.startSchedule)
-  ) {
+  if (!isValidTime(chargingProfile.chargingSchedule.startSchedule)) {
     logger.error(
       `${logPrefix} ${moduleName}.canProceedChargingProfile: Charging profile id ${chargingProfile.chargingProfileId} has an invalid startSchedule date defined`
     )
     return false
   }
-  if (
-    chargingProfile.chargingSchedule.duration != null &&
-    !Number.isSafeInteger(chargingProfile.chargingSchedule.duration)
-  ) {
+  if (!Number.isSafeInteger(chargingProfile.chargingSchedule.duration)) {
     logger.error(
       `${logPrefix} ${moduleName}.canProceedChargingProfile: Charging profile id ${chargingProfile.chargingProfileId} has non integer duration defined`
     )
index b50c062008b9b1388d9ea21cfeb21ac3ba0018ce..f00a558971dad96a44b682150735f823d96fa63f 100644 (file)
@@ -48,9 +48,10 @@ export class IdTagsCache {
     chargingStation: ChargingStation,
     connectorId: number
   ): string {
-    const hashId = chargingStation.stationInfo.hashId
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    const idTagsFile = getIdTagsFile(chargingStation.stationInfo)!
+    const hashId = chargingStation.stationInfo!.hashId
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    const idTagsFile = getIdTagsFile(chargingStation.stationInfo!)!
     switch (distribution) {
       case IdTagDistribution.RANDOM:
         return this.getRandomIdTag(hashId, idTagsFile)
@@ -108,12 +109,13 @@ export class IdTagsCache {
 
   private getConnectorAffinityIdTag (chargingStation: ChargingStation, connectorId: number): string {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    const file = getIdTagsFile(chargingStation.stationInfo)!
+    const file = getIdTagsFile(chargingStation.stationInfo!)!
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const idTags = this.getIdTags(file)!
     const addressableKey = this.getIdTagsCacheIndexesAddressableKey(
       file,
-      chargingStation.stationInfo.hashId
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      chargingStation.stationInfo!.hashId
     )
     this.idTagsCachesAddressableIndexes.set(
       addressableKey,
index ef965b1b7366e760aca7111e50d885cc99f8fc98..fcda613ecc433f894f1c6adda8176bcd311dc932 100644 (file)
@@ -111,14 +111,14 @@ export class SharedLRUCache {
     chargingStationConfiguration: ChargingStationConfiguration
   ): boolean {
     return (
-      chargingStationConfiguration?.configurationKey != null &&
-      chargingStationConfiguration?.stationInfo != null &&
-      chargingStationConfiguration?.automaticTransactionGenerator != null &&
-      chargingStationConfiguration?.configurationHash != null &&
-      isNotEmptyArray(chargingStationConfiguration?.configurationKey) &&
+      chargingStationConfiguration.configurationKey != null &&
+      chargingStationConfiguration.stationInfo != null &&
+      chargingStationConfiguration.automaticTransactionGenerator != null &&
+      chargingStationConfiguration.configurationHash != null &&
+      isNotEmptyArray(chargingStationConfiguration.configurationKey) &&
       !isEmptyObject(chargingStationConfiguration.stationInfo) &&
       !isEmptyObject(chargingStationConfiguration.automaticTransactionGenerator) &&
-      isNotEmptyString(chargingStationConfiguration?.configurationHash)
+      isNotEmptyString(chargingStationConfiguration.configurationHash)
     )
   }
 }
index 06f847c5a8b3990ed66fa0fe01d3d7769914418d..2407418601bacbbc4cc4bdf290c1f1477ed04a61 100644 (file)
@@ -273,7 +273,8 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
     const [uuid, command, requestPayload] = validatedMessageEvent.data as BroadcastChannelRequest
     if (
       requestPayload.hashIds != null &&
-      !requestPayload.hashIds.includes(this.chargingStation.stationInfo.hashId)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      !requestPayload.hashIds.includes(this.chargingStation.stationInfo!.hashId)
     ) {
       return
     }
@@ -290,7 +291,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
       commandResponse = await this.commandHandler(command, requestPayload)
       if (commandResponse == null || isEmptyObject(commandResponse)) {
         responsePayload = {
-          hashId: this.chargingStation.stationInfo.hashId,
+          hashId: this.chargingStation.stationInfo?.hashId,
           status: ResponseStatus.SUCCESS
         }
       } else {
@@ -306,7 +307,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
         error
       )
       responsePayload = {
-        hashId: this.chargingStation.stationInfo.hashId,
+        hashId: this.chargingStation.stationInfo?.hashId,
         status: ResponseStatus.FAILURE,
         command,
         requestPayload,
@@ -362,12 +363,12 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
     const responseStatus = this.commandResponseToResponseStatus(command, commandResponse)
     if (responseStatus === ResponseStatus.SUCCESS) {
       return {
-        hashId: this.chargingStation.stationInfo.hashId,
+        hashId: this.chargingStation.stationInfo?.hashId,
         status: responseStatus
       }
     }
     return {
-      hashId: this.chargingStation.stationInfo.hashId,
+      hashId: this.chargingStation.stationInfo?.hashId,
       status: responseStatus,
       command,
       requestPayload,
@@ -389,18 +390,18 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
               | StartTransactionResponse
               | StopTransactionResponse
               | AuthorizeResponse
-          )?.idTagInfo?.status === AuthorizationStatus.ACCEPTED
+          ).idTagInfo?.status === AuthorizationStatus.ACCEPTED
         ) {
           return ResponseStatus.SUCCESS
         }
         return ResponseStatus.FAILURE
       case BroadcastChannelProcedureName.BOOT_NOTIFICATION:
-        if (commandResponse?.status === RegistrationStatusEnumType.ACCEPTED) {
+        if (commandResponse.status === RegistrationStatusEnumType.ACCEPTED) {
           return ResponseStatus.SUCCESS
         }
         return ResponseStatus.FAILURE
       case BroadcastChannelProcedureName.DATA_TRANSFER:
-        if (commandResponse?.status === DataTransferStatus.ACCEPTED) {
+        if (commandResponse.status === DataTransferStatus.ACCEPTED) {
           return ResponseStatus.SUCCESS
         }
         return ResponseStatus.FAILURE
index 11127ec95ebbf21b86b67df30890d99a68a5f6b3..3e34782f47a7d3d440bdf5719a899121a412ff4f 100644 (file)
@@ -94,7 +94,7 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
         responsesFailed: this.responses
           .get(uuid)
           ?.responses.map((response) => {
-            if (response != null && response.status === ResponseStatus.FAILURE) {
+            if (response.status === ResponseStatus.FAILURE) {
               return response
             }
             return undefined
index e2e8dcba7ed846a4de3ecf8a25bc84bca00e11f4..0cd676472a1d3adf36e901d5700a383476ed3078 100644 (file)
@@ -120,8 +120,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
   >
 
   public constructor () {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_16)
     this.incomingRequestHandlers = new Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>([
@@ -454,7 +454,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     logger.info(
       `${chargingStation.logPrefix()} ${type} reset command received, simulating it. The station will be back online in ${formatDurationMilliSeconds(
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        chargingStation.stationInfo.resetTime!
+        chargingStation.stationInfo!.resetTime!
       )}`
     )
     return OCPP16Constants.OCPP_RESPONSE_ACCEPTED
@@ -643,12 +643,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       csChargingProfiles.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE &&
       connectorId > 0 &&
       connectorStatus?.transactionStarted === true &&
-      csChargingProfiles.transactionId !== connectorStatus?.transactionId
+      csChargingProfiles.transactionId !== connectorStatus.transactionId
     ) {
       logger.error(
         `${chargingStation.logPrefix()} Trying to set transaction charging profile(s) on connector ${connectorId} with a different transaction id ${
           csChargingProfiles.transactionId
-        } than the started transaction id ${connectorStatus?.transactionId}`
+        } than the started transaction id ${connectorStatus.transactionId}`
       )
       return OCPP16Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
     }
@@ -694,7 +694,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
     if (
-      isEmptyArray(connectorStatus?.chargingProfiles) &&
+      isEmptyArray(connectorStatus.chargingProfiles) &&
       isEmptyArray(chargingStation.getConnectorStatus(0)?.chargingProfiles)
     ) {
       return OCPP16Constants.OCPP_RESPONSE_REJECTED
@@ -713,8 +713,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     let compositeSchedule: OCPP16ChargingSchedule | undefined
     for (const chargingProfile of chargingProfiles) {
       if (
-        chargingProfile.chargingSchedule?.startSchedule == null &&
-        connectorStatus?.transactionStarted === true
+        chargingProfile.chargingSchedule.startSchedule == null &&
+        connectorStatus.transactionStarted === true
       ) {
         logger.debug(
           `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
@@ -722,11 +722,11 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
           } has no startSchedule defined. Trying to set it to the connector current transaction start date`
         )
         // OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
-        chargingProfile.chargingSchedule.startSchedule = connectorStatus?.transactionStart
+        chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
       }
       if (
-        chargingProfile.chargingSchedule?.startSchedule != null &&
-        !isDate(chargingProfile.chargingSchedule?.startSchedule)
+        chargingProfile.chargingSchedule.startSchedule != null &&
+        !isDate(chargingProfile.chargingSchedule.startSchedule)
       ) {
         logger.warn(
           `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
@@ -735,12 +735,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         )
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         chargingProfile.chargingSchedule.startSchedule = convertToDate(
-          chargingProfile.chargingSchedule?.startSchedule
+          chargingProfile.chargingSchedule.startSchedule
         )!
       }
       if (
-        chargingProfile.chargingSchedule?.startSchedule != null &&
-        chargingProfile.chargingSchedule?.duration == null
+        chargingProfile.chargingSchedule.startSchedule != null &&
+        chargingProfile.chargingSchedule.duration == null
       ) {
         logger.debug(
           `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
@@ -932,9 +932,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       )
     }
     const remoteStartTransactionLogMsg = `
-      ${chargingStation.logPrefix()} Transaction remotely STARTED on ${
-        chargingStation.stationInfo.chargingStationId
-      }#${transactionConnectorId} for idTag '${idTag}'`
+      ${chargingStation.logPrefix()} Transaction remotely STARTED on ${chargingStation.stationInfo
+        ?.chargingStationId}#${transactionConnectorId} for idTag '${idTag}'`
     await OCPP16ServiceUtils.sendAndSetConnectorStatus(
       chargingStation,
       transactionConnectorId,
@@ -1046,7 +1045,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     connectorId: number,
     chargingProfile: OCPP16ChargingProfile
   ): boolean {
-    if (chargingProfile?.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) {
+    if (chargingProfile.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) {
       OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, chargingProfile)
       logger.debug(
         `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
@@ -1110,10 +1109,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       return OCPP16Constants.OCPP_RESPONSE_EMPTY
     }
     let { retrieveDate } = commandPayload
-    if (
-      chargingStation.stationInfo.firmwareStatus != null &&
-      chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed
-    ) {
+    if (chargingStation.stationInfo?.firmwareStatus !== OCPP16FirmwareStatus.Installed) {
       logger.warn(
         `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
       )
@@ -1122,15 +1118,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     retrieveDate = convertToDate(retrieveDate)!
     const now = Date.now()
-    if (retrieveDate?.getTime() <= now) {
+    if (retrieveDate.getTime() <= now) {
       this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION)
     } else {
-      setTimeout(
-        () => {
-          this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION)
-        },
-        retrieveDate?.getTime() - now
-      )
+      setTimeout(() => {
+        this.updateFirmwareSimulation(chargingStation).catch(Constants.EMPTY_FUNCTION)
+      }, retrieveDate.getTime() - now)
     }
     return OCPP16Constants.OCPP_RESPONSE_EMPTY
   }
@@ -1147,7 +1140,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       for (const [evseId, evseStatus] of chargingStation.evses) {
         if (evseId > 0) {
           for (const [connectorId, connectorStatus] of evseStatus.connectors) {
-            if (connectorStatus?.transactionStarted === false) {
+            if (connectorStatus.transactionStarted === false) {
               await OCPP16ServiceUtils.sendAndSetConnectorStatus(
                 chargingStation,
                 connectorId,
@@ -1177,7 +1170,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
       status: OCPP16FirmwareStatus.Downloading
     })
-    chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Downloading
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    chargingStation.stationInfo!.firmwareStatus = OCPP16FirmwareStatus.Downloading
     if (
       chargingStation.stationInfo?.firmwareUpgrade?.failureStatus ===
       OCPP16FirmwareStatus.DownloadFailed
@@ -1187,10 +1181,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       OCPP16FirmwareStatusNotificationRequest,
       OCPP16FirmwareStatusNotificationResponse
       >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
-        status: chargingStation.stationInfo?.firmwareUpgrade?.failureStatus
+        status: chargingStation.stationInfo.firmwareUpgrade.failureStatus
       })
       chargingStation.stationInfo.firmwareStatus =
-        chargingStation.stationInfo?.firmwareUpgrade?.failureStatus
+        chargingStation.stationInfo.firmwareUpgrade.failureStatus
       return
     }
     await sleep(secondsToMilliseconds(getRandomInteger(maxDelay, minDelay)))
@@ -1200,7 +1194,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
       status: OCPP16FirmwareStatus.Downloaded
     })
-    chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Downloaded
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    chargingStation.stationInfo!.firmwareStatus = OCPP16FirmwareStatus.Downloaded
     let wasTransactionsStarted = false
     let transactionsStarted: boolean
     do {
@@ -1220,7 +1215,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
           for (const [evseId, evseStatus] of chargingStation.evses) {
             if (evseId > 0) {
               for (const [connectorId, connectorStatus] of evseStatus.connectors) {
-                if (connectorStatus?.status !== OCPP16ChargePointStatus.Unavailable) {
+                if (connectorStatus.status !== OCPP16ChargePointStatus.Unavailable) {
                   await OCPP16ServiceUtils.sendAndSetConnectorStatus(
                     chargingStation,
                     connectorId,
@@ -1259,7 +1254,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
       status: OCPP16FirmwareStatus.Installing
     })
-    chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installing
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    chargingStation.stationInfo!.firmwareStatus = OCPP16FirmwareStatus.Installing
     if (
       chargingStation.stationInfo?.firmwareUpgrade?.failureStatus ===
       OCPP16FirmwareStatus.InstallationFailed
@@ -1269,10 +1265,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       OCPP16FirmwareStatusNotificationRequest,
       OCPP16FirmwareStatusNotificationResponse
       >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
-        status: chargingStation.stationInfo?.firmwareUpgrade?.failureStatus
+        status: chargingStation.stationInfo.firmwareUpgrade.failureStatus
       })
       chargingStation.stationInfo.firmwareStatus =
-        chargingStation.stationInfo?.firmwareUpgrade?.failureStatus
+        chargingStation.stationInfo.firmwareUpgrade.failureStatus
       return
     }
     if (chargingStation.stationInfo?.firmwareUpgrade?.reset === true) {
@@ -1305,7 +1301,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         const logFiles = readdirSync(resolve(dirname(fileURLToPath(import.meta.url)), '../'))
           .filter((file) => file.endsWith('.log'))
           .map((file) => join('./', file))
-        const diagnosticsArchive = `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`
+        const diagnosticsArchive = `${chargingStation.stationInfo?.chargingStationId}_logs.tar.gz`
         create({ gzip: true }, logFiles).pipe(createWriteStream(diagnosticsArchive))
         ftpClient = new Client()
         const accessResponse = await ftpClient.access({
@@ -1349,24 +1345,18 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
             >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
               status: OCPP16DiagnosticsStatus.Uploaded
             })
-            if (ftpClient != null) {
-              ftpClient.close()
-            }
+            ftpClient.close()
             return { fileName: diagnosticsArchive }
           }
           throw new OCPPError(
             ErrorType.GENERIC_ERROR,
-            `Diagnostics transfer failed with error code ${accessResponse.code}${
-              uploadResponse?.code != null && `|${uploadResponse?.code}`
-            }`,
+            `Diagnostics transfer failed with error code ${accessResponse.code}|${uploadResponse.code}`,
             OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
           )
         }
         throw new OCPPError(
           ErrorType.GENERIC_ERROR,
-          `Diagnostics transfer failed with error code ${accessResponse.code}${
-            uploadResponse?.code != null && `|${uploadResponse?.code}`
-          }`,
+          `Diagnostics transfer failed with error code ${accessResponse.code}|${uploadResponse?.code}`,
           OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
         )
       } catch (error) {
@@ -1376,9 +1366,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
           status: OCPP16DiagnosticsStatus.UploadFailed
         })
-        if (ftpClient != null) {
-          ftpClient.close()
-        }
+        ftpClient?.close()
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         return this.handleIncomingRequestError<GetDiagnosticsResponse>(
           chargingStation,
index 37e7019c1a4f3f9f7a870a29ceb338ebe1606fff..124ffba16b48a7dfaea2dbbaea9fdfefb209e27a 100644 (file)
@@ -35,8 +35,8 @@ export class OCPP16RequestService extends OCPPRequestService {
   protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>
 
   public constructor (ocppResponseService: OCPPResponseService) {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_16, ocppResponseService)
     this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>([
@@ -180,21 +180,21 @@ export class OCPP16RequestService extends OCPPRequestService {
         return {
           idTag: Constants.DEFAULT_IDTAG,
           meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId(
-            commandParams?.connectorId as number,
+            commandParams.connectorId as number,
             true
           ),
           timestamp: new Date(),
           ...(OCPP16ServiceUtils.hasReservation(
             chargingStation,
-            commandParams?.connectorId as number,
-            commandParams?.idTag as string
+            commandParams.connectorId as number,
+            commandParams.idTag as string
           ) && {
             // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
             reservationId: chargingStation.getReservationBy(
               'connectorId',
               chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved
                 ? 0
-                : (commandParams?.connectorId as number)
+                : (commandParams.connectorId as number)
             )!.reservationId
           }),
           ...commandParams
@@ -203,14 +203,14 @@ export class OCPP16RequestService extends OCPPRequestService {
         chargingStation.stationInfo?.transactionDataMeterValues === true &&
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           (connectorId = chargingStation.getConnectorIdByTransactionId(
-            commandParams?.transactionId as number
+            commandParams.transactionId as number
           )!)
         energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
-          commandParams?.transactionId as number,
+          commandParams.transactionId as number,
           true
         )
         return {
-          idTag: chargingStation.getTransactionIdTag(commandParams?.transactionId as number),
+          idTag: chargingStation.getTransactionIdTag(commandParams.transactionId as number),
           meterStop: energyActiveImportRegister,
           timestamp: new Date(),
           ...(chargingStation.stationInfo?.transactionDataMeterValues === true && {
index f3855a1abeea5ea0c66ab6acb525e54ef7e828d5..3f311ba56e2687691644f41d04720d170466f412 100644 (file)
@@ -66,8 +66,8 @@ export class OCPP16ResponseService extends OCPPResponseService {
   private readonly jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>
 
   public constructor () {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_16)
     this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
@@ -442,7 +442,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       for (const [evseId, evseStatus] of chargingStation.evses) {
         if (evseId > 0) {
           for (const [connectorId, connectorStatus] of evseStatus.connectors) {
-            if (connectorStatus?.authorizeIdTag === requestPayload.idTag) {
+            if (connectorStatus.authorizeIdTag === requestPayload.idTag) {
               authorizeConnectorId = connectorId
               break
             }
@@ -505,10 +505,12 @@ export class OCPP16ResponseService extends OCPPResponseService {
       chargingStation.getAuthorizeRemoteTxRequests() &&
       chargingStation.getLocalAuthListEnabled() &&
       chargingStation.hasIdTags() &&
-      connectorStatus?.idTagLocalAuthorized === false
+      connectorStatus.idTagLocalAuthorized === false
     ) {
       logger.error(
-        `${chargingStation.logPrefix()} Trying to start a transaction with a not local authorized idTag ${connectorStatus?.localAuthorizeIdTag} on connector id ${connectorId}`
+        `${chargingStation.logPrefix()} Trying to start a transaction with a not local authorized idTag ${
+          connectorStatus.localAuthorizeIdTag
+        } on connector id ${connectorId}`
       )
       await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
       return
@@ -517,42 +519,50 @@ export class OCPP16ResponseService extends OCPPResponseService {
       connectorStatus?.transactionRemoteStarted === true &&
       chargingStation.getAuthorizeRemoteTxRequests() &&
       chargingStation.stationInfo?.remoteAuthorization === true &&
-      connectorStatus?.idTagLocalAuthorized === false &&
-      connectorStatus?.idTagAuthorized === false
+      connectorStatus.idTagLocalAuthorized === false &&
+      connectorStatus.idTagAuthorized === false
     ) {
       logger.error(
-        `${chargingStation.logPrefix()} Trying to start a transaction with a not authorized idTag ${connectorStatus?.authorizeIdTag} on connector id ${connectorId}`
+        `${chargingStation.logPrefix()} Trying to start a transaction with a not authorized idTag ${
+          connectorStatus.authorizeIdTag
+        } on connector id ${connectorId}`
       )
       await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
       return
     }
     if (
       connectorStatus?.idTagAuthorized === true &&
-      connectorStatus?.authorizeIdTag !== requestPayload.idTag
+      connectorStatus.authorizeIdTag !== requestPayload.idTag
     ) {
       logger.error(
         `${chargingStation.logPrefix()} Trying to start a transaction with an idTag ${
           requestPayload.idTag
-        } different from the authorize request one ${connectorStatus?.authorizeIdTag} on connector id ${connectorId}`
+        } different from the authorize request one ${
+          connectorStatus.authorizeIdTag
+        } on connector id ${connectorId}`
       )
       await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
       return
     }
     if (
       connectorStatus?.idTagLocalAuthorized === true &&
-      connectorStatus?.localAuthorizeIdTag !== requestPayload.idTag
+      connectorStatus.localAuthorizeIdTag !== requestPayload.idTag
     ) {
       logger.error(
         `${chargingStation.logPrefix()} Trying to start a transaction with an idTag ${
           requestPayload.idTag
-        } different from the local authorized one ${connectorStatus?.localAuthorizeIdTag} on connector id ${connectorId}`
+        } different from the local authorized one ${
+          connectorStatus.localAuthorizeIdTag
+        } on connector id ${connectorId}`
       )
       await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
       return
     }
     if (connectorStatus?.transactionStarted === true) {
       logger.error(
-        `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}`
+        `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${
+          connectorStatus.transactionIdTag
+        }`
       )
       return
     }
@@ -560,9 +570,11 @@ export class OCPP16ResponseService extends OCPPResponseService {
       for (const [evseId, evseStatus] of chargingStation.evses) {
         if (evseStatus.connectors.size > 1) {
           for (const [id, status] of evseStatus.connectors) {
-            if (id !== connectorId && status?.transactionStarted === true) {
+            if (id !== connectorId && status.transactionStarted === true) {
               logger.error(
-                `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${status?.transactionIdTag}`
+                `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${
+                  status.transactionIdTag
+                }`
               )
               await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
               return
@@ -589,7 +601,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       payload.transactionId = convertToInt(payload.transactionId)
     }
 
-    if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
+    if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
       connectorStatus.transactionStarted = true
       connectorStatus.transactionStart = requestPayload.timestamp
       connectorStatus.transactionId = payload.transactionId
@@ -645,12 +657,15 @@ export class OCPP16ResponseService extends OCPPResponseService {
         OCPP16ChargePointStatus.Charging
       )
       logger.info(
-        `${chargingStation.logPrefix()} Transaction with id ${payload.transactionId} STARTED on ${
-          chargingStation.stationInfo.chargingStationId
-        }#${connectorId} for idTag '${requestPayload.idTag}'`
+        `${chargingStation.logPrefix()} Transaction with id ${
+          payload.transactionId
+        } STARTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for idTag '${
+          requestPayload.idTag
+        }'`
       )
-      if (chargingStation.stationInfo.powerSharedByConnectors === true) {
-        ++chargingStation.powerDivider
+      if (chargingStation.stationInfo?.powerSharedByConnectors === true) {
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        ++chargingStation.powerDivider!
       }
       const configuredMeterValueSampleInterval = getConfigurationKey(
         chargingStation,
@@ -666,9 +681,8 @@ export class OCPP16ResponseService extends OCPPResponseService {
       logger.warn(
         `${chargingStation.logPrefix()} Starting transaction with id ${
           payload.transactionId
-        } REJECTED on ${
-          chargingStation.stationInfo.chargingStationId
-        }#${connectorId} with status '${payload.idTagInfo?.status}', idTag '${
+        } REJECTED on ${chargingStation.stationInfo
+          ?.chargingStationId}#${connectorId} with status '${payload.idTagInfo.status}', idTag '${
           requestPayload.idTag
         }'${
           OCPP16ServiceUtils.hasReservation(chargingStation, connectorId, requestPayload.idTag)
@@ -714,8 +728,8 @@ export class OCPP16ResponseService extends OCPPResponseService {
       return
     }
     chargingStation.stationInfo?.beginEndMeterValues === true &&
-      chargingStation.stationInfo?.ocppStrictCompliance === false &&
-      chargingStation.stationInfo?.outOfOrderEndMeterValues === true &&
+      chargingStation.stationInfo.ocppStrictCompliance === false &&
+      chargingStation.stationInfo.outOfOrderEndMeterValues === true &&
       (await chargingStation.ocppRequestService.requestHandler<
       OCPP16MeterValuesRequest,
       OCPP16MeterValuesResponse
@@ -746,20 +760,20 @@ export class OCPP16ResponseService extends OCPPResponseService {
         OCPP16ChargePointStatus.Available
       )
     }
-    if (chargingStation.stationInfo.powerSharedByConnectors === true) {
-      chargingStation.powerDivider--
+    if (chargingStation.stationInfo?.powerSharedByConnectors === true) {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      chargingStation.powerDivider!--
     }
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId)!)
     chargingStation.stopMeterValues(transactionConnectorId)
     const logMsg = `${chargingStation.logPrefix()} Transaction with id ${
       requestPayload.transactionId
-    } STOPPED on ${
-      chargingStation.stationInfo.chargingStationId
-    }#${transactionConnectorId} with status '${payload.idTagInfo?.status}'`
+    } STOPPED on ${chargingStation.stationInfo
+      ?.chargingStationId}#${transactionConnectorId} with status '${payload.idTagInfo?.status}'`
     if (
       payload.idTagInfo == null ||
-      payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED
+      payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
     ) {
       logger.info(logMsg)
     } else {
index bbdf2e51a8eac5b5d08d18252eb939f22c66724d..db964227a3d59324cc89dd791d14feb0652c2fce 100644 (file)
@@ -61,7 +61,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
   public static buildTransactionBeginMeterValue (
     chargingStation: ChargingStation,
     connectorId: number,
-    meterStart: number
+    meterStart: number | undefined
   ): OCPP16MeterValue {
     const meterValue: OCPP16MeterValue = {
       timestamp: new Date(),
@@ -126,7 +126,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
-      if (connectorStatus?.transactionStarted === true) {
+      if (connectorStatus.transactionStarted === true) {
         response = OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
       }
       connectorStatus.availability = availabilityType
@@ -166,19 +166,19 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
     }
     let cpReplaced = false
     if (isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) {
-      chargingStation
+      for (const [index, chargingProfile] of chargingStation
         .getConnectorStatus(connectorId)
-        ?.chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
-          if (
-            chargingProfile.chargingProfileId === cp.chargingProfileId ||
-            (chargingProfile.stackLevel === cp.stackLevel &&
-              chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
-          ) {
-            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-            chargingStation.getConnectorStatus(connectorId)!.chargingProfiles![index] = cp
-            cpReplaced = true
-          }
-        })
+        ?.chargingProfiles?.entries() ?? []) {
+        if (
+          chargingProfile.chargingProfileId === cp.chargingProfileId ||
+          (chargingProfile.stackLevel === cp.stackLevel &&
+            chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
+        ) {
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          chargingStation.getConnectorStatus(connectorId)!.chargingProfiles![index] = cp
+          cpReplaced = true
+        }
+      }
     }
     !cpReplaced && chargingStation.getConnectorStatus(connectorId)?.chargingProfiles?.push(cp)
   }
@@ -451,11 +451,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         OCPP16ChargePointStatus.Reserved &&
         connectorReservation != null &&
         !hasReservationExpired(connectorReservation) &&
-        connectorReservation?.idTag === idTag) ||
+        connectorReservation.idTag === idTag) ||
       (chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved &&
         chargingStationReservation != null &&
         !hasReservationExpired(chargingStationReservation) &&
-        chargingStationReservation?.idTag === idTag)
+        chargingStationReservation.idTag === idTag)
     ) {
       logger.debug(
         `${chargingStation.logPrefix()} Connector id ${connectorId} has a valid reservation for idTag ${idTag}: %j`,
index e0b8fa54fefac42f70d7812e2b84f496abc46390..db509ecd9ba939ba8c99241604cdc15c6e968f6b 100644 (file)
@@ -26,8 +26,8 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
   >
 
   public constructor () {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_20)
     this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
index a9a7302847cc0932cdf6cba057858959c9f0e9e1..b54e491ac0af548360b8e9ae1dad19990803bb39 100644 (file)
@@ -27,8 +27,8 @@ export class OCPP20RequestService extends OCPPRequestService {
   protected jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>
 
   public constructor (ocppResponseService: OCPPResponseService) {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_20, ocppResponseService)
     this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>([
index c8345676125b1594309aa7d950846764cb10c028..704d3a15fa305d4f9c6a07b1f4e0d8215e5113ed 100644 (file)
@@ -34,8 +34,8 @@ export class OCPP20ResponseService extends OCPPResponseService {
   private readonly jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>
 
   public constructor () {
-    // if (new.target?.name === moduleName) {
-    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`)
+    // if (new.target.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_20)
     this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
index 62e58661054f973028b9fae1f1713cac5a99db27..ea3e7b7312c03027dcae25c43a85b20a9cd42a7d 100644 (file)
@@ -73,14 +73,14 @@ export abstract class OCPPIncomingRequestService {
       `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
       error
     )
-    if (params?.throwError === false && params?.errorResponse != null) {
-      return params?.errorResponse
+    if (params.throwError === false && params.errorResponse != null) {
+      return params.errorResponse
     }
-    if (params?.throwError === true && params?.errorResponse == null) {
+    if (params.throwError === true && params.errorResponse == null) {
       throw error
     }
-    if (params?.throwError === true && params?.errorResponse != null) {
-      return params?.errorResponse
+    if (params.throwError === true && params.errorResponse != null) {
+      return params.errorResponse
     }
   }
 
@@ -111,7 +111,7 @@ export abstract class OCPPIncomingRequestService {
 
   protected handleRequestClearCache (chargingStation: ChargingStation): ClearCacheResponse {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    if (chargingStation.idTagsCache.deleteIdTags(getIdTagsFile(chargingStation.stationInfo)!)) {
+    if (chargingStation.idTagsCache.deleteIdTags(getIdTagsFile(chargingStation.stationInfo!)!)) {
       return OCPPConstants.OCPP_RESPONSE_ACCEPTED
     }
     return OCPPConstants.OCPP_RESPONSE_REJECTED
index e78f71c56d1300137c12800c8f343e2a1ae9791c..1d698bd894fcaa6dd2d6194f77f0e036b8a19856 100644 (file)
@@ -454,7 +454,7 @@ export abstract class OCPPRequestService {
                 // Resolve response
                 resolve(messagePayload)
               }
-            } else if (error != null) {
+            } else {
               handleSendError(
                 new OCPPError(
                   ErrorType.GENERIC_ERROR,
@@ -483,7 +483,7 @@ export abstract class OCPPRequestService {
     }
     throw new OCPPError(
       ErrorType.SECURITY_ERROR,
-      `Cannot send command ${commandName} PDU when the charging station is in ${chargingStation?.bootNotificationResponse?.status} state on the central server`,
+      `Cannot send command ${commandName} PDU when the charging station is in ${chargingStation.bootNotificationResponse?.status} state on the central server`,
       commandName
     )
   }
index bd228564d9649ce2eddd153dab9aba1903704125..cb802d12c9397b2d787e86258a598376657cb50a 100644 (file)
@@ -139,7 +139,7 @@ const isIdTagLocalAuthorized = (chargingStation: ChargingStation, idTag: string)
     isNotEmptyString(
       chargingStation.idTagsCache
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        .getIdTags(getIdTagsFile(chargingStation.stationInfo)!)
+        .getIdTags(getIdTagsFile(chargingStation.stationInfo!)!)
         ?.find((tag) => tag === idTag)
     )
   )
@@ -161,7 +161,7 @@ const isIdTagRemoteAuthorized = async (
           idTag
         }
       )
-    )?.idTagInfo?.status === AuthorizationStatus.ACCEPTED
+    ).idTagInfo.status === AuthorizationStatus.ACCEPTED
   )
 }
 
@@ -237,8 +237,9 @@ const checkConnectorStatusTransition = (
   }
   if (!transitionAllowed) {
     logger.warn(
-      `${chargingStation.logPrefix()} OCPP ${chargingStation.stationInfo
-        ?.ocppVersion} connector id ${connectorId} status transition from '${
+      `${chargingStation.logPrefix()} OCPP ${
+        chargingStation.stationInfo.ocppVersion
+      } connector id ${connectorId} status transition from '${
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         chargingStation.getConnectorStatus(connectorId)!.status
       }' to '${status}' is not allowed`
@@ -323,7 +324,7 @@ export const buildMeterValue = (
         if (
           chargingStation.getNumberOfPhases() !== 3 ||
           (chargingStation.getNumberOfPhases() === 3 &&
-            chargingStation.stationInfo?.mainVoltageMeterValues === true)
+            chargingStation.stationInfo.mainVoltageMeterValues === true)
         ) {
           meterValue.sampledValue.push(
             buildSampledValue(voltageSampledValueTemplate, voltageMeasurandValue)
@@ -365,7 +366,7 @@ export const buildMeterValue = (
               phaseLineToNeutralValue as MeterValuePhase
             )
           )
-          if (chargingStation.stationInfo?.phaseLineToLineVoltageMeterValues === true) {
+          if (chargingStation.stationInfo.phaseLineToLineVoltageMeterValues === true) {
             const phaseLineToLineValue = `L${phase}-L${
               (phase + 1) % chargingStation.getNumberOfPhases() !== 0
                 ? (phase + 1) % chargingStation.getNumberOfPhases()
@@ -443,17 +444,17 @@ export const buildMeterValue = (
       }
       if (powerSampledValueTemplate != null) {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        checkMeasurandPowerDivider(chargingStation, powerSampledValueTemplate.measurand!)
+        checkMeasurandPowerDivider(chargingStation, powerSampledValueTemplate.measurand)
         const errMsg = `MeterValues measurand ${
           powerSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-        }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
+        }: Unknown ${chargingStation.stationInfo.currentOutType} currentOutType in template file ${
           chargingStation.templateFile
         }, cannot calculate ${
           powerSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
         } measurand value`
         // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
         const powerMeasurandValues: MeasurandValues = {} as MeasurandValues
-        const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1
+        const unitDivider = powerSampledValueTemplate.unit === MeterValueUnit.KILO_WATT ? 1000 : 1
         const connectorMaximumAvailablePower =
           chargingStation.getConnectorMaximumAvailablePower(connectorId)
         const connectorMaximumPower = Math.round(connectorMaximumAvailablePower)
@@ -464,7 +465,7 @@ export const buildMeterValue = (
         const connectorMinimumPowerPerPhase = Math.round(
           connectorMinimumPower / chargingStation.getNumberOfPhases()
         )
-        switch (chargingStation.stationInfo?.currentOutType) {
+        switch (chargingStation.stationInfo.currentOutType) {
           case CurrentType.AC:
             if (chargingStation.getNumberOfPhases() === 3) {
               const defaultFluctuatedPowerPerPhase = isNotEmptyString(
@@ -477,7 +478,7 @@ export const buildMeterValue = (
                     connectorMinimumPower / unitDivider,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumPower / unitDivider
                     }
                   ) / chargingStation.getNumberOfPhases(),
@@ -495,7 +496,7 @@ export const buildMeterValue = (
                     connectorMinimumPowerPerPhase / unitDivider,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumPowerPerPhase / unitDivider
                     }
                   ),
@@ -513,7 +514,7 @@ export const buildMeterValue = (
                     connectorMinimumPowerPerPhase / unitDivider,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumPowerPerPhase / unitDivider
                     }
                   ),
@@ -531,7 +532,7 @@ export const buildMeterValue = (
                     connectorMinimumPowerPerPhase / unitDivider,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumPowerPerPhase / unitDivider
                     }
                   ),
@@ -569,7 +570,7 @@ export const buildMeterValue = (
                     connectorMinimumPower / unitDivider,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumPower / unitDivider
                     }
                   ),
@@ -597,7 +598,7 @@ export const buildMeterValue = (
                   connectorMinimumPower / unitDivider,
                   {
                     limitationEnabled:
-                        chargingStation.stationInfo?.customValueLimitationMeterValues,
+                        chargingStation.stationInfo.customValueLimitationMeterValues,
                     fallbackValue: connectorMinimumPower / unitDivider
                   }
                 ),
@@ -710,10 +711,10 @@ export const buildMeterValue = (
       }
       if (currentSampledValueTemplate != null) {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        checkMeasurandPowerDivider(chargingStation, currentSampledValueTemplate.measurand!)
+        checkMeasurandPowerDivider(chargingStation, currentSampledValueTemplate.measurand)
         const errMsg = `MeterValues measurand ${
           currentSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
-        }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
+        }: Unknown ${chargingStation.stationInfo.currentOutType} currentOutType in template file ${
           chargingStation.templateFile
         }, cannot calculate ${
           currentSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
@@ -724,7 +725,7 @@ export const buildMeterValue = (
           chargingStation.getConnectorMaximumAvailablePower(connectorId)
         const connectorMinimumAmperage = currentSampledValueTemplate.minimumValue ?? 0
         let connectorMaximumAmperage: number
-        switch (chargingStation.stationInfo?.currentOutType) {
+        switch (chargingStation.stationInfo.currentOutType) {
           case CurrentType.AC:
             connectorMaximumAmperage = ACElectricUtils.amperagePerPhaseFromPower(
               chargingStation.getNumberOfPhases(),
@@ -743,7 +744,7 @@ export const buildMeterValue = (
                     connectorMinimumAmperage,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumAmperage
                     }
                   ),
@@ -761,7 +762,7 @@ export const buildMeterValue = (
                     connectorMinimumAmperage,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumAmperage
                     }
                   ),
@@ -779,7 +780,7 @@ export const buildMeterValue = (
                     connectorMinimumAmperage,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumAmperage
                     }
                   ),
@@ -797,7 +798,7 @@ export const buildMeterValue = (
                     connectorMinimumAmperage,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumAmperage
                     }
                   ),
@@ -826,7 +827,7 @@ export const buildMeterValue = (
                     connectorMinimumAmperage,
                     {
                       limitationEnabled:
-                          chargingStation.stationInfo?.customValueLimitationMeterValues,
+                          chargingStation.stationInfo.customValueLimitationMeterValues,
                       fallbackValue: connectorMinimumAmperage
                     }
                   ),
@@ -857,7 +858,7 @@ export const buildMeterValue = (
                   connectorMinimumAmperage,
                   {
                     limitationEnabled:
-                        chargingStation.stationInfo?.customValueLimitationMeterValues,
+                        chargingStation.stationInfo.customValueLimitationMeterValues,
                     fallbackValue: connectorMinimumAmperage
                   }
                 ),
@@ -931,9 +932,9 @@ export const buildMeterValue = (
       energySampledValueTemplate = getSampledValueTemplate(chargingStation, connectorId)
       if (energySampledValueTemplate != null) {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        checkMeasurandPowerDivider(chargingStation, energySampledValueTemplate.measurand!)
+        checkMeasurandPowerDivider(chargingStation, energySampledValueTemplate.measurand)
         const unitDivider =
-          energySampledValueTemplate?.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
+          energySampledValueTemplate.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
         const connectorMaximumAvailablePower =
           chargingStation.getConnectorMaximumAvailablePower(connectorId)
         const connectorMaximumEnergyRounded = roundTo(
@@ -951,7 +952,7 @@ export const buildMeterValue = (
               connectorMaximumEnergyRounded,
               connectorMinimumEnergyRounded,
               {
-                limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues,
+                limitationEnabled: chargingStation.stationInfo.customValueLimitationMeterValues,
                 fallbackValue: connectorMinimumEnergyRounded,
                 unitMultiplier: unitDivider
               }
@@ -1011,7 +1012,7 @@ export const buildMeterValue = (
 export const buildTransactionEndMeterValue = (
   chargingStation: ChargingStation,
   connectorId: number,
-  meterStop: number
+  meterStop: number | undefined
 ): MeterValue => {
   let meterValue: MeterValue
   let sampledValueTemplate: SampledValueTemplate | undefined
@@ -1045,7 +1046,7 @@ export const buildTransactionEndMeterValue = (
 
 const checkMeasurandPowerDivider = (
   chargingStation: ChargingStation,
-  measurandType: MeterValueMeasurand
+  measurandType: MeterValueMeasurand | undefined
 ): void => {
   if (chargingStation.powerDivider == null) {
     const errMsg = `MeterValues measurand ${
@@ -1053,7 +1054,7 @@ const checkMeasurandPowerDivider = (
     }: powerDivider is undefined`
     logger.error(`${chargingStation.logPrefix()} ${errMsg}`)
     throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, RequestCommand.METER_VALUES)
-  } else if (chargingStation?.powerDivider <= 0) {
+  } else if (chargingStation.powerDivider <= 0) {
     const errMsg = `MeterValues measurand ${
       measurandType ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
     }: powerDivider have zero or below value ${chargingStation.powerDivider}`
@@ -1077,7 +1078,7 @@ const getLimitFromSampledValueTemplateCustomValue = (
     ...options
   }
   const parsedValue = parseInt(value ?? '')
-  if (options?.limitationEnabled === true) {
+  if (options.limitationEnabled === true) {
     return max(
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       min((!isNaN(parsedValue) ? parsedValue : Infinity) * options.unitMultiplier!, maxLimit),
@@ -1175,12 +1176,11 @@ const buildSampledValue = (
   context?: MeterValueContext,
   phase?: MeterValuePhase
 ): SampledValue => {
-  const sampledValueContext = context ?? sampledValueTemplate?.context
+  const sampledValueContext = context ?? sampledValueTemplate.context
   const sampledValueLocation =
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    sampledValueTemplate?.location ?? getMeasurandDefaultLocation(sampledValueTemplate.measurand!)
-  const sampledValuePhase = phase ?? sampledValueTemplate?.phase
-  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+    sampledValueTemplate.location ?? getMeasurandDefaultLocation(sampledValueTemplate.measurand!)
+  const sampledValuePhase = phase ?? sampledValueTemplate.phase
   return {
     ...(sampledValueTemplate.unit != null && {
       unit: sampledValueTemplate.unit
@@ -1190,9 +1190,9 @@ const buildSampledValue = (
       measurand: sampledValueTemplate.measurand
     }),
     ...(sampledValueLocation != null && { location: sampledValueLocation }),
-    ...(value != null && { value: value.toString() }),
+    ...{ value: value.toString() },
     ...(sampledValuePhase != null && { phase: sampledValuePhase })
-  } as SampledValue
+  } satisfies SampledValue
 }
 
 const getMeasurandDefaultLocation = (
@@ -1271,7 +1271,7 @@ export class OCPPServiceUtils {
       isRequestCommand &&
       chargingStation.stationInfo?.commandsSupport?.outgoingCommands?.[command] != null
     ) {
-      return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command]
+      return chargingStation.stationInfo.commandsSupport.outgoingCommands[command]
     }
     logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`)
     return false
@@ -1290,9 +1290,9 @@ export class OCPPServiceUtils {
       return true
     } else if (
       isIncomingRequestCommand &&
-      chargingStation.stationInfo?.commandsSupport?.incomingCommands?.[command] != null
+      chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] != null
     ) {
-      return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command]
+      return chargingStation.stationInfo.commandsSupport.incomingCommands[command]
     }
     logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`)
     return false
@@ -1309,7 +1309,7 @@ export class OCPPServiceUtils {
       isMessageTrigger &&
       chargingStation.stationInfo?.messageTriggerSupport?.[messageTrigger] != null
     ) {
-      return chargingStation.stationInfo?.messageTriggerSupport[messageTrigger]
+      return chargingStation.stationInfo.messageTriggerSupport[messageTrigger]
     }
     logger.error(
       `${chargingStation.logPrefix()} Unknown incoming OCPP message trigger '${messageTrigger}'`
@@ -1337,8 +1337,8 @@ export class OCPPServiceUtils {
       if (isDate(obj![key])) {
         // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
         (obj![key] as string) = (obj![key] as Date).toISOString()
-        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
-      } else if (obj![key] !== null && typeof obj![key] === 'object') {
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-condition
+      } else if (typeof obj![key] === 'object' && obj![key] !== null) {
         // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
         OCPPServiceUtils.convertDateToISOString<T>(obj![key] as T)
       }
index 78f0468322bf35b02ef28c25c16400ec72753803..cd6167389cf159d44c3b6118e20d3446473d01d3 100644 (file)
@@ -103,7 +103,8 @@ export abstract class AbstractUIServer {
   private isBasicAuthEnabled (): boolean {
     return (
       this.uiServerConfiguration.authentication?.enabled === true &&
-      this.uiServerConfiguration.authentication?.type === AuthenticationType.BASIC_AUTH
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+      this.uiServerConfiguration.authentication.type === AuthenticationType.BASIC_AUTH
     )
   }
 
index 0b6eee9feb5bb783610a5f9001d4f04f6b7fe008..27b9e8458fbe19bd1e3822f60f57fea7d9c84645 100644 (file)
@@ -122,13 +122,7 @@ export class UIHttpServer extends AbstractUIServer {
             const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload
             this.uiServices
               .get(version)
-              ?.requestHandler(
-                this.buildProtocolRequest(
-                  uuid,
-                  procedureName,
-                  body ?? Constants.EMPTY_FROZEN_OBJECT
-                )
-              )
+              ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body))
               .then((protocolResponse?: ProtocolResponse) => {
                 if (protocolResponse != null) {
                   this.sendResponse(protocolResponse)
index 097533e0b493196bc7a0c864907ba1dbde3f5984..6d6dc6df9fcd6d66a77ec3455d1f0ef76787c08e 100644 (file)
@@ -80,7 +80,7 @@ export class UIWebSocketServer extends AbstractUIServer {
       })
     })
     this.httpServer.on('connect', (req: IncomingMessage, socket: Duplex, _head: Buffer) => {
-      if (req.headers?.connection !== 'Upgrade' || req.headers?.upgrade !== 'websocket') {
+      if (req.headers.connection !== 'Upgrade' || req.headers.upgrade !== 'websocket') {
         socket.write(`HTTP/1.1 ${StatusCodes.BAD_REQUEST} Bad Request\r\n\r\n`)
         socket.destroy()
       }
@@ -115,18 +115,20 @@ export class UIWebSocketServer extends AbstractUIServer {
   }
 
   public sendResponse (response: ProtocolResponse): void {
-    const responseId = response?.[0]
+    const responseId = response[0]
     try {
       if (this.hasResponseHandler(responseId)) {
         const ws = this.responseHandlers.get(responseId) as WebSocket
-        if (ws?.readyState === WebSocket.OPEN) {
+        if (ws.readyState === WebSocket.OPEN) {
           ws.send(JSON.stringify(response))
         } else {
           logger.error(
             `${this.logPrefix(
               moduleName,
               'sendResponse'
-            )} Error at sending response id '${responseId}', WebSocket is not open: ${ws?.readyState}`
+            )} Error at sending response id '${responseId}', WebSocket is not open: ${
+              ws.readyState
+            }`
           )
         }
       } else {
@@ -162,7 +164,7 @@ export class UIWebSocketServer extends AbstractUIServer {
 
   private broadcastToClients (message: string): void {
     for (const client of this.webSocketServer.clients) {
-      if (client?.readyState === WebSocket.OPEN) {
+      if (client.readyState === WebSocket.OPEN) {
         client.send(message)
       }
     }
@@ -191,6 +193,7 @@ export class UIWebSocketServer extends AbstractUIServer {
       return false
     }
 
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
     if (request.length !== 3) {
       logger.error(
         `${this.logPrefix(moduleName, 'validateRawDataRequest')} UI protocol request is malformed:`,
@@ -199,7 +202,7 @@ export class UIWebSocketServer extends AbstractUIServer {
       return false
     }
 
-    if (!validateUUID(request?.[0])) {
+    if (!validateUUID(request[0])) {
       logger.error(
         `${this.logPrefix(
           moduleName,
index 847401013e606759a98dde88ab295a7c6b80e08d..a4edbcaa1ac2b9195b9ff19bec57697530586c41 100644 (file)
@@ -164,7 +164,7 @@ export abstract class AbstractUIService {
     if (isNotEmptyArray(payload.hashIds)) {
       payload.hashIds = payload.hashIds
         ?.map((hashId) => {
-          if (hashId != null && this.uiServer.chargingStations.has(hashId)) {
+          if (this.uiServer.chargingStations.has(hashId)) {
             return hashId
           }
           logger.warn(
index f61d095874f9dafbde0df907b7ad60e58f504098..88ea748c635bbdea9023c24819740d8184e749dc 100644 (file)
@@ -41,19 +41,19 @@ export class PerformanceStatistics {
   PerformanceStatistics
   >()
 
-  private readonly objId: string
-  private readonly objName: string
+  private readonly objId: string | undefined
+  private readonly objName: string | undefined
   private performanceObserver!: PerformanceObserver
   private readonly statistics: Statistics
   private displayInterval?: NodeJS.Timeout
 
-  private constructor (objId: string, objName: string, uri: URL) {
-    this.objId = objId
-    this.objName = objName
+  private constructor (objId: string | undefined, objName: string | undefined, uri: URL) {
+    this.objId = objId ?? 'Object id not specified'
+    this.objName = objName ?? 'Object name not specified'
     this.initializePerformanceObserver()
     this.statistics = {
-      id: this.objId ?? 'Object id not specified',
-      name: this.objName ?? 'Object name not specified',
+      id: this.objId,
+      name: this.objName,
       uri: uri.toString(),
       createdAt: new Date(),
       statisticsData: new Map()
@@ -164,7 +164,7 @@ export class PerformanceStatistics {
     this.stopLogStatisticsInterval()
     performance.clearMarks()
     performance.clearMeasures()
-    this.performanceObserver?.disconnect()
+    this.performanceObserver.disconnect()
   }
 
   public restart (): void {
@@ -185,7 +185,7 @@ export class PerformanceStatistics {
   }
 
   private logStatistics (): void {
-    logger.info(`${this.logPrefix()}`, {
+    logger.info(this.logPrefix(), {
       ...this.statistics,
       statisticsData: JSONStringifyWithMapSupport(this.statistics.statisticsData)
     })
index 3fe5e58eed7aef75f35ae120e97033bd3cdb02d5..f44d9f2b35adc56ca0d9d503e927ccfac6eae760 100644 (file)
@@ -47,7 +47,7 @@ export class JsonFileStorage extends Storage {
   public open (): void {
     JsonFileStorage.performanceRecords = new Map<string, Statistics>()
     try {
-      if (this?.fd == null) {
+      if (this.fd == null) {
         if (!existsSync(dirname(this.dbName))) {
           mkdirSync(dirname(this.dbName), { recursive: true })
         }
@@ -66,9 +66,9 @@ export class JsonFileStorage extends Storage {
   public close (): void {
     JsonFileStorage.performanceRecords.clear()
     try {
-      if (this?.fd != null) {
+      if (this.fd != null) {
         closeSync(this.fd)
-        delete this?.fd
+        delete this.fd
       }
     } catch (error) {
       handleFileException(
@@ -81,7 +81,7 @@ export class JsonFileStorage extends Storage {
   }
 
   private checkPerformanceRecordsFile (): void {
-    if (this?.fd == null) {
+    if (this.fd == null) {
       throw new BaseError(
         `${this.logPrefix} Performance records '${this.dbName}' file descriptor not found`
       )
index 4e2091a52401e91f85a534ac0b0466d8cd5cbf00..3eec553d26a56c013d9df95c6b30c9f7e43a310e 100644 (file)
@@ -1,12 +1,6 @@
 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
-import {
-  type Configuration,
-  type Connection,
-  type IDatabaseDriver,
-  MikroORM,
-  type Options
-} from '@mikro-orm/core'
+import { type Configuration, MikroORM, type Options } from '@mikro-orm/core'
 import { TsMorphMetadataProvider } from '@mikro-orm/reflection'
 
 import { Storage } from './Storage.js'
@@ -40,7 +34,7 @@ export class MikroOrmStorage extends Storage {
 
   public async open (): Promise<void> {
     try {
-      if (this?.orm == null) {
+      if (this.orm == null) {
         this.orm = await MikroORM.init(this.getOptions(), true)
       }
     } catch (error) {
@@ -50,9 +44,9 @@ export class MikroOrmStorage extends Storage {
 
   public async close (): Promise<void> {
     try {
-      if (this?.orm != null) {
+      if (this.orm != null) {
         await this.orm.close()
-        delete this?.orm
+        delete this.orm
       }
     } catch (error) {
       this.handleDBError(this.storageType, error as Error)
@@ -63,15 +57,10 @@ export class MikroOrmStorage extends Storage {
     if (this.storageType === StorageType.SQLITE) {
       return `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
     }
-    return (
-      this.storageUri.pathname.replace(/(?:^\/)|(?:\/$)/g, '') ??
-      Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME
-    )
+    return this.storageUri.pathname.replace(/(?:^\/)|(?:\/$)/g, '')
   }
 
-  private getOptions ():
-  | Configuration<IDatabaseDriver<Connection>>
-  | Options<IDatabaseDriver<Connection>> {
+  private getOptions (): Configuration | Options {
     return {
       metadataProvider: TsMorphMetadataProvider,
       entities: [PerformanceRecord, PerformanceData],
index 70256fc953d358e215f5ee9124d0997314fe3e8a..009d8161d4412a88da47676bc63268bda884501c 100644 (file)
@@ -15,9 +15,7 @@ export class MongoDBStorage extends Storage {
     super(storageUri, logPrefix)
     this.client = new MongoClient(this.storageUri.toString())
     this.connected = false
-    this.dbName =
-      this.storageUri.pathname.replace(/(?:^\/)|(?:\/$)/g, '') ??
-      Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME
+    this.dbName = this.storageUri.pathname.replace(/(?:^\/)|(?:\/$)/g, '')
   }
 
   public async storePerformanceStatistics (performanceStatistics: Statistics): Promise<void> {
@@ -34,7 +32,7 @@ export class MongoDBStorage extends Storage {
 
   public async open (): Promise<void> {
     try {
-      if (!this.connected && this?.client != null) {
+      if (!this.connected && this.client != null) {
         await this.client.connect()
         this.connected = true
       }
@@ -45,7 +43,7 @@ export class MongoDBStorage extends Storage {
 
   public async close (): Promise<void> {
     try {
-      if (this.connected && this?.client != null) {
+      if (this.connected && this.client != null) {
         await this.client.close()
         this.connected = false
       }
@@ -55,7 +53,7 @@ export class MongoDBStorage extends Storage {
   }
 
   private checkDBConnection (): void {
-    if (this?.client == null) {
+    if (this.client == null) {
       throw new BaseError(
         `${this.logPrefix} ${this.getDBNameFromStorageType(
           StorageType.MONGO_DB
index 8ee2a7018ee6dfc911d67218d07ef272df6293d9..4724681558894674f6bb1d3decd2ea5953c276a3 100644 (file)
@@ -35,7 +35,7 @@ export abstract class Storage {
       }'${inTableOrCollectionStr}:`,
       error
     )
-    if (params?.throwError === true) {
+    if (params.throwError === true) {
       throw error
     }
   }
index ac4ea8e6b3ad353c9878b7e039e0fe47893ac745..9ea1a0e615bc3a3d5beb7b9d9481aa9bff2d1a08 100644 (file)
@@ -34,7 +34,7 @@ export interface BroadcastChannelRequestPayload extends RequestPayload {
 
 export interface BroadcastChannelResponsePayload
   extends Omit<ResponsePayload, 'hashIdsSucceeded' | 'hashIdsFailed' | 'responsesFailed'> {
-  hashId: string
+  hashId: string | undefined
 }
 
 export interface MessageEvent {
index 8b0b1c8fa532c3afdd879dd6f6418576e5531139..596b685cbf7be0636f4ec7a0ba74c0668bf0c16b 100644 (file)
@@ -45,7 +45,7 @@ type ConfigurationSectionType =
 
 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
 export class Configuration {
-  public static configurationChangeCallback: () => Promise<void>
+  public static configurationChangeCallback?: () => Promise<void>
 
   private static readonly configurationFile = join(
     dirname(fileURLToPath(import.meta.url)),
@@ -327,7 +327,8 @@ export class Configuration {
         ] as StationTemplateUrl[])
     Configuration.getConfigurationData()?.stationTemplateUrls.forEach(
       (stationTemplateUrl: StationTemplateUrl) => {
-        if (stationTemplateUrl?.['numberOfStation' as keyof StationTemplateUrl] !== undefined) {
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+        if (stationTemplateUrl['numberOfStation' as keyof StationTemplateUrl] !== undefined) {
           console.error(
             `${chalk.green(logPrefix())} ${chalk.red(
               `Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`
@@ -495,7 +496,7 @@ export class Configuration {
         string,
         unknown
         >
-      )?.[key] !== undefined
+      )[key] !== undefined
     ) {
       console.error(
         `${chalk.green(logPrefix())} ${chalk.red(
index 1fd0482bd78b1bd9996961b8c07c8a359f3c2982..41a61acc41491cca0d614db9b1c5576a67e821e5 100644 (file)
@@ -57,21 +57,21 @@ export const handleFileException = (
     default:
       logMsg = `${fileType} file ${file} error:`
   }
-  if (params?.consoleOut === true) {
+  if (params.consoleOut === true) {
     logMsg = `${logMsg} `
-    if (params?.throwError === true) {
+    if (params.throwError === true) {
       console.error(`${chalk.green(prefix)}${chalk.red(logMsg)}`, error)
     } else {
       console.warn(`${chalk.green(prefix)}${chalk.yellow(logMsg)}`, error)
     }
-  } else if (params?.consoleOut === false) {
-    if (params?.throwError === true) {
+  } else if (params.consoleOut === false) {
+    if (params.throwError === true) {
       logger.error(`${prefix}${logMsg}`, error)
     } else {
       logger.warn(`${prefix}${logMsg}`, error)
     }
   }
-  if (params?.throwError === true) {
+  if (params.throwError === true) {
     throw error
   }
 }
@@ -84,7 +84,7 @@ export const handleSendMessageError = (
 ): void => {
   setDefaultErrorParams(params, { throwError: false, consoleOut: false })
   logger.error(`${chargingStation.logPrefix()} Request command '${commandName}' error:`, error)
-  if (params?.throwError === true) {
+  if (params.throwError === true) {
     throw error
   }
 }
index 842b8bfe5644332e52acb7c6d833cfcc552a4bce..a61bf94ab29d34879805982692a867b2e7285f4b 100644 (file)
@@ -51,12 +51,13 @@ export const buildPerformanceStatisticsMessage = (
 const buildChargingStationDataPayload = (chargingStation: ChargingStation): ChargingStationData => {
   return {
     started: chargingStation.started,
-    stationInfo: chargingStation.stationInfo,
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    stationInfo: chargingStation.stationInfo!,
     connectors: buildConnectorsStatus(chargingStation),
     evses: buildEvsesStatus(chargingStation, OutputFormat.worker),
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     ocppConfiguration: chargingStation.ocppConfiguration!,
-    wsState: chargingStation?.wsConnection?.readyState,
+    wsState: chargingStation.wsConnection?.readyState,
     bootNotificationResponse: chargingStation.bootNotificationResponse,
     ...(chargingStation.automaticTransactionGenerator != null && {
       automaticTransactionGenerator:
index cef15f52a07045294f65d17fdccab44b85ae6f58..deb1624b803f451adc9822ea32cc383e00a3e313 100644 (file)
@@ -54,6 +54,7 @@ export const nthPercentile = (dataSet: number[], percentile: number): number =>
   }
   const percentileIndexBase = (percentile / 100) * (sortedDataSet.length - 1)
   const percentileIndexInteger = Math.floor(percentileIndexBase)
+  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
   if (sortedDataSet[percentileIndexInteger + 1] != null) {
     return (
       sortedDataSet[percentileIndexInteger] +
index 87ea9a2cc1f96c5ad19aab5e6a20760c126f8489..b8083596b2618a3b5c2360d15a4fc6542a00c9dd 100644 (file)
@@ -154,7 +154,7 @@ export const getRandomFloat = (max = Number.MAX_VALUE, min = 0): number => {
 
 export const getRandomInteger = (max = Constants.MAX_RANDOM_INTEGER, min = 0): number => {
   max = Math.floor(max)
-  if (min != null && min !== 0) {
+  if (min !== 0) {
     min = Math.ceil(min)
     return Math.floor(randomInt(min, max + 1))
   }
@@ -175,7 +175,7 @@ export const roundTo = (numberValue: number, scale: number): number => {
 }
 
 export const getRandomFloatRounded = (max = Number.MAX_VALUE, min = 0, scale = 2): number => {
-  if (min != null && min !== 0) {
+  if (min !== 0) {
     return roundTo(getRandomFloat(max, min), scale)
   }
   return roundTo(getRandomFloat(max), scale)
@@ -294,7 +294,7 @@ export const isNotEmptyArray = (object: unknown): boolean => {
 }
 
 export const isEmptyObject = (obj: object): boolean => {
-  if (obj?.constructor !== Object) {
+  if (obj.constructor !== Object) {
     return false
   }
   // Iterates over the keys of an object, if
@@ -371,8 +371,8 @@ export const getWebSocketCloseEventStatusString = (code: number): string => {
     }
   }
   if (
-    WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] !==
-    undefined
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] != null
   ) {
     return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString]
   }
@@ -395,6 +395,7 @@ export const once = <T, A extends any[], R>(
 ): ((...args: A) => R) => {
   let result: R
   return (...args: A) => {
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
     if (fn != null) {
       result = fn.apply<T, A, R>(context, args)
       ;(fn as unknown as undefined) = (context as unknown as undefined) = undefined
index 38d762762634ad01339d081e2db0205d6b609e89..9a10e6f2afa1de4c463dd8a2803917b61f5b76b5 100644 (file)
@@ -19,7 +19,7 @@ export abstract class WorkerAbstract<T extends WorkerData> {
    * @param workerScript -
    * @param workerOptions -
    */
-  constructor (workerScript: string, workerOptions: WorkerOptions) {
+  constructor (workerScript: string | undefined, workerOptions: WorkerOptions) {
     if (workerScript == null) {
       throw new TypeError('Worker script is not defined')
     }
index 6574dcc25b24edbaf51c4a838fd0419840dbd5b1..817536f0237251b88af5c242fb0800914e4574d5 100644 (file)
@@ -38,7 +38,7 @@ export class WorkerDynamicPool extends WorkerAbstract<WorkerData> {
   }
 
   get emitter (): EventEmitterAsyncResource | undefined {
-    return this.pool?.emitter
+    return this.pool.emitter
   }
 
   /** @inheritDoc */
index a2a0e759d7004f65658d89ff60b684b5d53dad99..836690413516bf9c241cbbd7d1d352992c04eec8 100644 (file)
@@ -37,7 +37,7 @@ export class WorkerFixedPool extends WorkerAbstract<WorkerData> {
   }
 
   get emitter (): EventEmitterAsyncResource | undefined {
-    return this.pool?.emitter
+    return this.pool.emitter
   }
 
   /** @inheritDoc */
index b8e0e31fb641b94080933a87f06779009e95e43a..ea5d654cdd001f599e6af1b670e61e494852430c 100644 (file)
@@ -105,9 +105,6 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     if (!this.started) {
       throw new Error('Cannot add a WorkerSet element: not started')
     }
-    if (this.workerSet == null) {
-      throw new Error("Cannot add a WorkerSet element: 'workerSet' property does not exist")
-    }
     const workerSetElement = await this.getWorkerSetElement()
     workerSetElement.worker.postMessage({
       event: WorkerMessageEvents.startWorkerElement,