X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=7c4b098d3de215a7781d0909572b55e665518013;hb=b13beb880ee7647456c703b93657a42c3ec2e5ee;hp=df029c3a6b8245963839d4c093442985bd537253;hpb=a807045be19c1ed4996a44d8c2c8774e926dc6dc;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index df029c3a..7c4b098d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -143,8 +143,6 @@ import { handleFileException, isNotEmptyArray, isNotEmptyString, - isNullOrUndefined, - isUndefined, logPrefix, logger, min, @@ -274,7 +272,7 @@ export class ChargingStation extends EventEmitter { } public inUnknownState (): boolean { - return isNullOrUndefined(this?.bootNotificationResponse?.status) + return this?.bootNotificationResponse?.status == null } public inPendingState (): boolean { @@ -348,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! ) { @@ -570,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` @@ -735,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) { @@ -796,7 +791,7 @@ export class ChargingStation extends EventEmitter { } public getAutomaticTransactionGeneratorConfiguration (): AutomaticTransactionGeneratorConfiguration { - if (isNullOrUndefined(this.automaticTransactionGeneratorConfiguration)) { + if (this.automaticTransactionGeneratorConfiguration == null) { let automaticTransactionGeneratorConfiguration: | AutomaticTransactionGeneratorConfiguration | undefined @@ -817,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 { @@ -885,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 }) }) } @@ -968,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 @@ -1046,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 @@ -1145,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 } @@ -1211,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) @@ -1234,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() @@ -1301,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, @@ -1324,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 }) @@ -1332,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, @@ -1343,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, @@ -1359,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()) { @@ -1395,18 +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.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,