build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 6df137f82e7469e7b7cb07d6c95f1a6805f34f89..7c4b098d3de215a7781d0909572b55e665518013 100644 (file)
@@ -38,6 +38,7 @@ import {
   getMaxNumberOfEvses,
   getNumberOfReservableConnectors,
   getPhaseRotationValue,
+  hasFeatureProfile,
   hasReservationExpired,
   initializeConnectorsMapStatus,
   propagateSerialNumber,
@@ -142,8 +143,6 @@ import {
   handleFileException,
   isNotEmptyArray,
   isNotEmptyString,
-  isNullOrUndefined,
-  isUndefined,
   logPrefix,
   logger,
   min,
@@ -273,7 +272,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public inUnknownState (): boolean {
-    return isNullOrUndefined(this?.bootNotificationResponse?.status)
+    return this?.bootNotificationResponse?.status == null
   }
 
   public inPendingState (): boolean {
@@ -347,7 +346,7 @@ export class ChargingStation extends EventEmitter {
   public getConnectorMaximumAvailablePower (connectorId: number): number {
     let connectorAmperageLimitationPowerLimit: number | undefined
     if (
-      !isNullOrUndefined(this.getAmperageLimitation()) &&
+      this.getAmperageLimitation() != null &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       this.getAmperageLimitation()! < this.stationInfo.maximumAmperage!
     ) {
@@ -461,7 +460,7 @@ export class ChargingStation extends EventEmitter {
       this,
       StandardParametersKey.AuthorizeRemoteTxRequests
     )
-    return authorizeRemoteTxRequests !== undefined
+    return authorizeRemoteTxRequests != null
       ? convertToBoolean(authorizeRemoteTxRequests.value)
       : false
   }
@@ -471,16 +470,16 @@ export class ChargingStation extends EventEmitter {
       this,
       StandardParametersKey.LocalAuthListEnabled
     )
-    return localAuthListEnabled !== undefined ? convertToBoolean(localAuthListEnabled.value) : false
+    return localAuthListEnabled != null ? convertToBoolean(localAuthListEnabled.value) : false
   }
 
   public getHeartbeatInterval (): number {
     const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval)
-    if (HeartbeatInterval !== undefined) {
+    if (HeartbeatInterval != null) {
       return secondsToMilliseconds(convertToInt(HeartbeatInterval.value))
     }
     const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval)
-    if (HeartBeatInterval !== undefined) {
+    if (HeartBeatInterval != null) {
       return secondsToMilliseconds(convertToInt(HeartBeatInterval.value))
     }
     this.stationInfo?.autoRegister === false &&
@@ -507,7 +506,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public startHeartbeat (): void {
-    if (this.getHeartbeatInterval() > 0 && this.heartbeatSetInterval === undefined) {
+    if (this.getHeartbeatInterval() > 0 && this.heartbeatSetInterval == null) {
       this.heartbeatSetInterval = setInterval(() => {
         this.ocppRequestService
           .requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
@@ -523,7 +522,7 @@ export class ChargingStation extends EventEmitter {
           this.getHeartbeatInterval()
         )}`
       )
-    } else if (this.heartbeatSetInterval !== undefined) {
+    } else if (this.heartbeatSetInterval != null) {
       logger.info(
         `${this.logPrefix()} Heartbeat already started every ${formatDurationMilliSeconds(
           this.getHeartbeatInterval()
@@ -569,7 +568,7 @@ export class ChargingStation extends EventEmitter {
       return
     } else if (
       this.getConnectorStatus(connectorId)?.transactionStarted === true &&
-      isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionId)
+      this.getConnectorStatus(connectorId)?.transactionId == null
     ) {
       logger.error(
         `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction id`
@@ -613,7 +612,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public stopMeterValues (connectorId: number): void {
-    if (this.getConnectorStatus(connectorId)?.transactionSetInterval !== undefined) {
+    if (this.getConnectorStatus(connectorId)?.transactionSetInterval != null) {
       clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval)
     }
   }
@@ -734,10 +733,7 @@ export class ChargingStation extends EventEmitter {
     if (!checkChargingStation(this, this.logPrefix())) {
       return
     }
-    if (
-      !isNullOrUndefined(this.stationInfo.supervisionUser) &&
-      !isNullOrUndefined(this.stationInfo.supervisionPassword)
-    ) {
+    if (this.stationInfo.supervisionUser != null && this.stationInfo.supervisionPassword != null) {
       options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`
     }
     if (params?.closeOpened === true) {
@@ -795,7 +791,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   public getAutomaticTransactionGeneratorConfiguration (): AutomaticTransactionGeneratorConfiguration {
-    if (isNullOrUndefined(this.automaticTransactionGeneratorConfiguration)) {
+    if (this.automaticTransactionGeneratorConfiguration == null) {
       let automaticTransactionGeneratorConfiguration:
       | AutomaticTransactionGeneratorConfiguration
       | undefined
@@ -816,8 +812,7 @@ export class ChargingStation extends EventEmitter {
         ...automaticTransactionGeneratorConfiguration
       }
     }
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    return this.automaticTransactionGeneratorConfiguration!
+    return this.automaticTransactionGeneratorConfiguration
   }
 
   public getAutomaticTransactionGeneratorStatuses (): Status[] | undefined {
@@ -884,7 +879,7 @@ export class ChargingStation extends EventEmitter {
       transactionId,
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId!, true),
-      ...(isNullOrUndefined(reason) && { reason })
+      ...(reason != null && { reason })
     })
   }
 
@@ -897,7 +892,7 @@ export class ChargingStation extends EventEmitter {
 
   public async addReservation (reservation: Reservation): Promise<void> {
     const reservationFound = this.getReservationBy('reservationId', reservation.reservationId)
-    if (reservationFound !== undefined) {
+    if (reservationFound != null) {
       await this.removeReservation(reservationFound, ReservationTerminationReason.REPLACE_EXISTING)
     }
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -967,20 +962,15 @@ export class ChargingStation extends EventEmitter {
     connectorId?: number
   ): boolean {
     const reservation = this.getReservationBy('reservationId', reservationId)
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    const reservationExists = !isUndefined(reservation) && !hasReservationExpired(reservation!)
+    const reservationExists = reservation !== undefined && !hasReservationExpired(reservation)
     if (arguments.length === 1) {
       return !reservationExists
     } else if (arguments.length > 1) {
-      const userReservation = !isUndefined(idTag)
-        ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.getReservationBy('idTag', idTag!)
-        : undefined
+      const userReservation =
+        idTag !== undefined ? this.getReservationBy('idTag', idTag) : undefined
       const userReservationExists =
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        !isUndefined(userReservation) && !hasReservationExpired(userReservation!)
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0
+        userReservation !== undefined && !hasReservationExpired(userReservation)
+      const notConnectorZero = connectorId === undefined ? true : connectorId > 0
       const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0
       return (
         !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable
@@ -990,7 +980,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private setIntervalFlushMessageBuffer (): void {
-    if (this.flushMessageBufferSetInterval === undefined) {
+    if (this.flushMessageBufferSetInterval == null) {
       this.flushMessageBufferSetInterval = setInterval(() => {
         if (this.isWebSocketConnectionOpened() && this.inAcceptedState()) {
           this.flushMessageBuffer()
@@ -1003,7 +993,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private clearIntervalFlushMessageBuffer (): void {
-    if (this.flushMessageBufferSetInterval !== undefined) {
+    if (this.flushMessageBufferSetInterval != null) {
       clearInterval(this.flushMessageBufferSetInterval)
       delete this.flushMessageBufferSetInterval
     }
@@ -1045,7 +1035,7 @@ export class ChargingStation extends EventEmitter {
         this.wsConnection?.send(message, (error?: Error) => {
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           isRequest && PerformanceStatistics.endMeasure(commandName!, beginId!)
-          if (isNullOrUndefined(error)) {
+          if (error == null) {
             logger.debug(
               `${this.logPrefix()} >> Buffered ${getMessageTypeString(
                 messageType
@@ -1144,10 +1134,10 @@ export class ChargingStation extends EventEmitter {
       },
       stationTemplate?.firmwareUpgrade ?? {}
     )
-    stationInfo.resetTime = !isNullOrUndefined(stationTemplate?.resetTime)
-      ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      secondsToMilliseconds(stationTemplate.resetTime!)
-      : Constants.CHARGING_STATION_DEFAULT_RESET_TIME
+    stationInfo.resetTime =
+      stationTemplate?.resetTime != null
+        ? secondsToMilliseconds(stationTemplate.resetTime)
+        : Constants.CHARGING_STATION_DEFAULT_RESET_TIME
     return stationInfo
   }
 
@@ -1210,7 +1200,6 @@ export class ChargingStation extends EventEmitter {
     const stationConfiguration = this.getConfigurationFromFile()
     if (
       stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash &&
-      // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
       (stationConfiguration?.connectorsStatus != null || stationConfiguration?.evsesStatus != null)
     ) {
       checkConfiguration(stationConfiguration, this.logPrefix(), this.configurationFile)
@@ -1233,16 +1222,14 @@ export class ChargingStation extends EventEmitter {
         .exec(this.stationInfo.firmwareVersion!)
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         ?.slice(1, patternGroup! + 1)
-      if (!isNullOrUndefined(match)) {
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        const patchLevelIndex = match!.length - 1
-        // prettier-ignore
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        match![patchLevelIndex] = (convertToInt(match![patchLevelIndex]) +
-            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-            this.stationInfo.firmwareUpgrade!.versionUpgrade!.step!).toString()
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.stationInfo.firmwareVersion = match!.join('.')
+      if (match != null) {
+        const patchLevelIndex = match.length - 1
+        match[patchLevelIndex] = (
+          convertToInt(match[patchLevelIndex]) +
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          this.stationInfo.firmwareUpgrade!.versionUpgrade!.step!
+        ).toString()
+        this.stationInfo.firmwareVersion = match.join('.')
       }
     }
     this.saveStationInfo()
@@ -1300,17 +1287,17 @@ export class ChargingStation extends EventEmitter {
   }
 
   private initializeOcppConfiguration (): void {
-    if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartbeatInterval))) {
+    if (getConfigurationKey(this, StandardParametersKey.HeartbeatInterval) == null) {
       addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0')
     }
-    if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.HeartBeatInterval))) {
+    if (getConfigurationKey(this, StandardParametersKey.HeartBeatInterval) == null) {
       addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false })
     }
     if (
       this.stationInfo?.supervisionUrlOcppConfiguration === true &&
       isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      isNullOrUndefined(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!))
+      getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) == null
     ) {
       addConfigurationKey(
         this,
@@ -1323,7 +1310,7 @@ export class ChargingStation extends EventEmitter {
       this.stationInfo?.supervisionUrlOcppConfiguration === false &&
       isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey) &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      !isNullOrUndefined(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!))
+      getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!) != null
     ) {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       deleteConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey!, { save: false })
@@ -1331,7 +1318,7 @@ export class ChargingStation extends EventEmitter {
     if (
       isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      isNullOrUndefined(getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!))
+      getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) == null
     ) {
       addConfigurationKey(
         this,
@@ -1342,9 +1329,7 @@ export class ChargingStation extends EventEmitter {
         (this.stationInfo.maximumAmperage! * getAmperageLimitationUnitDivider(this.stationInfo)).toString()
       )
     }
-    if (
-      isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles))
-    ) {
+    if (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) {
       addConfigurationKey(
         this,
         StandardParametersKey.SupportedFeatureProfiles,
@@ -1358,18 +1343,14 @@ export class ChargingStation extends EventEmitter {
       { readonly: true },
       { overwrite: true }
     )
-    if (
-      isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData))
-    ) {
+    if (getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData) == null) {
       addConfigurationKey(
         this,
         StandardParametersKey.MeterValuesSampledData,
         MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
       )
     }
-    if (
-      isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation))
-    ) {
+    if (getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation) == null) {
       const connectorsPhaseRotation: string[] = []
       if (this.hasEvses) {
         for (const evseStatus of this.evses.values()) {
@@ -1394,20 +1375,16 @@ export class ChargingStation extends EventEmitter {
         connectorsPhaseRotation.toString()
       )
     }
-    if (
-      isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests))
-    ) {
+    if (getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests) == null) {
       addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true')
     }
     if (
-      isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled)) &&
-      getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)?.value?.includes(
-        SupportedFeatureProfiles.LocalAuthListManagement
-      ) === true
+      getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) == null &&
+      hasFeatureProfile(this, SupportedFeatureProfiles.LocalAuthListManagement) === true
     ) {
       addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false')
     }
-    if (isNullOrUndefined(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut))) {
+    if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) == null) {
       addConfigurationKey(
         this,
         StandardParametersKey.ConnectionTimeOut,
@@ -2072,7 +2049,7 @@ export class ChargingStation extends EventEmitter {
 
   // 0 for disabling
   private getConnectionTimeout (): number {
-    if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) !== undefined) {
+    if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut) != null) {
       return convertToInt(
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value! ??
@@ -2120,7 +2097,7 @@ 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!) !== undefined
+      getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!) != null
     ) {
       return (
         convertToInt(
@@ -2238,12 +2215,12 @@ export class ChargingStation extends EventEmitter {
 
   private startWebSocketPing (): void {
     const webSocketPingInterval: number =
-      getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) !== undefined
+      getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) != null
         ? convertToInt(
           getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value
         )
         : 0
-    if (webSocketPingInterval > 0 && this.webSocketPingSetInterval === undefined) {
+    if (webSocketPingInterval > 0 && this.webSocketPingSetInterval == null) {
       this.webSocketPingSetInterval = setInterval(() => {
         if (this.isWebSocketConnectionOpened()) {
           this.wsConnection?.ping()
@@ -2254,7 +2231,7 @@ export class ChargingStation extends EventEmitter {
           webSocketPingInterval
         )}`
       )
-    } else if (this.webSocketPingSetInterval !== undefined) {
+    } else if (this.webSocketPingSetInterval != null) {
       logger.info(
         `${this.logPrefix()} WebSocket ping already started every ${formatDurationSeconds(
           webSocketPingInterval
@@ -2268,7 +2245,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private stopWebSocketPing (): void {
-    if (this.webSocketPingSetInterval !== undefined) {
+    if (this.webSocketPingSetInterval != null) {
       clearInterval(this.webSocketPingSetInterval)
       delete this.webSocketPingSetInterval
     }
@@ -2314,7 +2291,7 @@ export class ChargingStation extends EventEmitter {
   }
 
   private stopHeartbeat (): void {
-    if (this.heartbeatSetInterval !== undefined) {
+    if (this.heartbeatSetInterval != null) {
       clearInterval(this.heartbeatSetInterval)
       delete this.heartbeatSetInterval
     }