logger,
logPrefix,
} from '../utils/index.js'
-import { DEFAULT_ELEMENTS_PER_WORKER, type WorkerAbstract, WorkerFactory } from '../worker/index.js'
+import {
+ DEFAULT_ELEMENTS_PER_WORKER,
+ DEFAULT_POOL_MAX_SIZE,
+ DEFAULT_POOL_MIN_SIZE,
+ type WorkerAbstract,
+ WorkerFactory,
+} from '../worker/index.js'
import { buildTemplateName, waitChargingStationEvents } from './Helpers.js'
import { UIServerFactory } from './ui-server/UIServerFactory.js'
}
public getLastContiguousIndex (templateName: string): number {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const indexes = [...this.templateStatistics.get(templateName)!.indexes]
- .concat(0)
- .sort((a, b) => a - b)
+ const templateStatistics = this.templateStatistics.get(templateName)
+ if (templateStatistics == null) {
+ return 0
+ }
+ const indexes = [...templateStatistics.indexes].concat(0).sort((a, b) => a - b)
for (let i = 0; i < indexes.length - 1; i++) {
if (indexes[i + 1] - indexes[i] !== 1) {
return indexes[i]
ConfigurationSection.performanceStorage
)
if (performanceStorageConfiguration.enabled === true) {
- this.storage = StorageFactory.getStorage(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- performanceStorageConfiguration.type!,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- performanceStorageConfiguration.uri!,
- this.logPrefix()
- )
- await this.storage.open()
+ const storageType = performanceStorageConfiguration.type
+ const storageUri = performanceStorageConfiguration.uri
+ if (storageType != null && storageUri != null) {
+ this.storage = StorageFactory.getStorage(storageType, storageUri, this.logPrefix())
+ await this.storage.open()
+ }
}
this.uiServer.setChargingStationTemplates(
Configuration.getStationTemplateUrls()?.map(stationTemplateUrl =>
this.uiServerStarted = true
}
// Start ChargingStation object instance in worker thread
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
+ for (const stationTemplateUrl of Configuration.getStationTemplateUrls() ?? []) {
const nbStations = stationTemplateUrl.numberOfStations
const sequentialAdd =
(Configuration.getConfigurationSection<WorkerConfiguration>(
}
private initializeCounters (): void {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const stationTemplateUrls = Configuration.getStationTemplateUrls()!
+ const stationTemplateUrls = Configuration.getStationTemplateUrls() ?? []
if (isNotEmptyArray(stationTemplateUrls)) {
for (const stationTemplateUrl of stationTemplateUrls) {
const templateName = buildTemplateName(stationTemplateUrl.file)
default:
elementsPerWorker = workerConfiguration.elementsPerWorker ?? DEFAULT_ELEMENTS_PER_WORKER
}
+ if (workerConfiguration.processType == null) {
+ throw new BaseError('Worker process type is not defined in configuration')
+ }
this.workerImplementation = WorkerFactory.getWorkerImplementation<
ChargingStationWorkerData,
ChargingStationInfo
dirname(fileURLToPath(import.meta.url)),
`ChargingStationWorker${extname(fileURLToPath(import.meta.url))}`
),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- workerConfiguration.processType!,
+ workerConfiguration.processType,
{
elementAddDelay: workerConfiguration.elementAddDelay,
elementsPerWorker,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- poolMaxSize: workerConfiguration.poolMaxSize!,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- poolMinSize: workerConfiguration.poolMinSize!,
+ poolMaxSize: workerConfiguration.poolMaxSize ?? DEFAULT_POOL_MAX_SIZE,
+ poolMinSize: workerConfiguration.poolMinSize ?? DEFAULT_POOL_MIN_SIZE,
poolOptions: {
messageHandler: this.messageHandler.bind(this) as MessageHandler<Worker>,
...(workerConfiguration.resourceLimits != null && {
if (this.uiServer.deleteChargingStationData(data.stationInfo.hashId)) {
this.uiServer.scheduleClientNotification()
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)!
- --templateStatistics.added
- templateStatistics.indexes.delete(data.stationInfo.templateIndex)
+ const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)
+ if (templateStatistics != null) {
+ --templateStatistics.added
+ templateStatistics.indexes.delete(data.stationInfo.templateIndex)
+ }
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventDeleted: Charging station ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (this.uiServer.setChargingStationData(data.stationInfo.hashId, data)) {
this.uiServer.scheduleClientNotification()
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++this.templateStatistics.get(data.stationInfo.templateName)!.started
+ const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)
+ if (templateStatistics != null) {
+ ++templateStatistics.started
+ }
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (this.uiServer.setChargingStationData(data.stationInfo.hashId, data)) {
this.uiServer.scheduleClientNotification()
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- --this.templateStatistics.get(data.stationInfo.templateName)!.started
+ const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)
+ if (templateStatistics != null) {
+ --templateStatistics.started
+ }
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
const connectorMaximumPower = (this.stationInfo?.maximumPower ?? 0) / (this.powerDivider ?? 1)
const chargingStationChargingProfilesLimit =
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- getChargingStationChargingProfilesLimit(this)! / this.powerDivider!
+ (getChargingStationChargingProfilesLimit(this) ?? Number.POSITIVE_INFINITY) /
+ (this.powerDivider ?? 1)
const connectorChargingProfilesLimit = getConnectorChargingProfilesLimit(this, connectorId)
return min(
Number.isNaN(connectorMaximumPower) ? Number.POSITIVE_INFINITY : connectorMaximumPower,
transactionId: number | string | undefined,
rounded = false
): number {
+ const connectorId = this.getConnectorIdByTransactionId(transactionId)
return this.getEnergyActiveImportRegister(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)!),
+ connectorId != null ? this.getConnectorStatus(connectorId) : undefined,
rounded
)
}
* @returns The number of phases (3 for AC, 0 for DC)
*/
public getNumberOfPhases (stationInfo?: ChargingStationInfo): number {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const localStationInfo = stationInfo ?? this.stationInfo!
+ const localStationInfo = stationInfo ?? this.stationInfo
switch (this.getCurrentOutType(stationInfo)) {
case CurrentType.AC:
- return localStationInfo.numberOfPhases ?? 3
+ return localStationInfo?.numberOfPhases ?? 3
case CurrentType.DC:
return 0
}
public getReserveConnectorZeroSupported (): boolean {
return convertToBoolean(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value
+ getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)?.value
)
}
public getVoltageOut (stationInfo?: ChargingStationInfo): Voltage {
return (
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- (stationInfo ?? this.stationInfo!).voltageOut ??
+ (stationInfo ?? this.stationInfo)?.voltageOut ??
getDefaultVoltageOut(this.getCurrentOutType(stationInfo), this.logPrefix(), this.templateFile)
)
}
}
public hasIdTags (): boolean {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return isNotEmptyArray(this.idTagsCache.getIdTags(getIdTagsFile(this.stationInfo!)!))
+ const idTagsFile = this.stationInfo != null ? getIdTagsFile(this.stationInfo) : undefined
+ return idTagsFile != null && isNotEmptyArray(this.idTagsCache.getIdTags(idTagsFile))
}
public inAcceptedState (): boolean {
reservation: Reservation,
reason: ReservationTerminationReason
): Promise<void> {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connector = this.getConnectorStatus(reservation.connectorId)!
+ const connectorStatus = this.getConnectorStatus(reservation.connectorId)
+ if (connectorStatus == null) {
+ logger.error(
+ `${this.logPrefix()} Trying to remove reservation on non-existent connector id ${reservation.connectorId.toString()}`
+ )
+ return
+ }
switch (reason) {
case ReservationTerminationReason.CONNECTOR_STATE_CHANGED:
case ReservationTerminationReason.TRANSACTION_STARTED:
- delete connector.reservation
+ delete connectorStatus.reservation
break
case ReservationTerminationReason.EXPIRED:
case ReservationTerminationReason.REPLACE_EXISTING:
} as unknown as StatusNotificationRequest,
{ send: reservation.connectorId !== 0 }
)
- delete connector.reservation
+ delete connectorStatus.reservation
break
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
} file have changed, reload`
)
this.sharedLRUCache.deleteChargingStationTemplate(this.templateFileHash)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo!)!)
+ const idTagsFile =
+ this.stationInfo != null ? getIdTagsFile(this.stationInfo) : undefined
+ if (idTagsFile != null) {
+ this.idTagsCache.deleteIdTags(idTagsFile)
+ }
OCPPAuthServiceFactory.clearInstance(this)
// Initialize
this.initialize()
break
case SupervisionUrlDistribution.CHARGING_STATION_AFFINITY:
case SupervisionUrlDistribution.ROUND_ROBIN:
- default:
- !Object.values(SupervisionUrlDistribution).includes(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- Configuration.getSupervisionUrlDistribution()!
- ) &&
+ default: {
+ const supervisionUrlDistribution = Configuration.getSupervisionUrlDistribution()
+ if (
+ supervisionUrlDistribution != null &&
+ !Object.values(SupervisionUrlDistribution).includes(supervisionUrlDistribution)
+ ) {
logger.warn(
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
- `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' in configuration from values '${SupervisionUrlDistribution.toString()}', defaulting to '${
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
+ `${this.logPrefix()} Unknown supervision url distribution '${supervisionUrlDistribution}' in configuration from values '${SupervisionUrlDistribution.toString()}', defaulting to '${
SupervisionUrlDistribution.CHARGING_STATION_AFFINITY
}'`
)
+ }
configuredSupervisionUrlIndex = (this.index - 1) % supervisionUrls.length
break
+ }
}
configuredSupervisionUrl = supervisionUrls[configuredSupervisionUrlIndex]
} else if (typeof supervisionUrls === 'string') {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- configuredSupervisionUrl = supervisionUrls!
+ configuredSupervisionUrl = supervisionUrls
}
if (isNotEmptyString(configuredSupervisionUrl)) {
return new URL(configuredSupervisionUrl)
private getCurrentOutType (stationInfo?: ChargingStationInfo): CurrentType {
return (
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- (stationInfo ?? this.stationInfo!).currentOutType ??
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- Constants.DEFAULT_STATION_INFO.currentOutType!
+ (stationInfo ?? this.stationInfo)?.currentOutType ??
+ Constants.DEFAULT_STATION_INFO.currentOutType ??
+ CurrentType.AC
)
}
}
private getMaximumAmperage (stationInfo?: ChargingStationInfo): number | undefined {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const maximumPower = (stationInfo ?? this.stationInfo!).maximumPower!
+ const localStationInfo = stationInfo ?? this.stationInfo
+ const maximumPower = localStationInfo?.maximumPower ?? 0
switch (this.getCurrentOutType(stationInfo)) {
case CurrentType.AC:
return ACElectricUtils.amperagePerPhaseFromPower(
}
private getStationInfoFromTemplate (): ChargingStationInfo {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const stationTemplate = this.getTemplateFromFile()!
+ const stationTemplate = this.getTemplateFromFile()
+ if (stationTemplate == null) {
+ const errorMsg = `Failed to read charging station template file ${this.templateFile}`
+ logger.error(`${this.logPrefix()} ${errorMsg}`)
+ throw new BaseError(errorMsg)
+ }
checkTemplate(stationTemplate, this.logPrefix(), this.templateFile)
const warnTemplateKeysDeprecationOnce = once(warnTemplateKeysDeprecation)
warnTemplateKeysDeprecationOnce(stationTemplate, this.logPrefix(), this.templateFile)
}
private getUseConnectorId0 (stationTemplate?: ChargingStationTemplate): boolean {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return stationTemplate?.useConnectorId0 ?? Constants.DEFAULT_STATION_INFO.useConnectorId0!
+ return (
+ stationTemplate?.useConnectorId0 ?? Constants.DEFAULT_STATION_INFO.useConnectorId0 ?? true
+ )
}
private handleErrorMessage (errorResponse: ErrorResponse): void {
{ errorDetails, errorMessage, errorType }
)
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const [, errorCallback, requestCommandName] = this.getCachedRequest(messageType, messageId)!
+ const cachedRequest = this.getCachedRequest(messageType, messageId)
+ if (cachedRequest == null) {
+ throw new OCPPError(
+ ErrorType.INTERNAL_ERROR,
+ `Cached request for error message id '${messageId}' is nullish`,
+ undefined,
+ { errorDetails, errorMessage, errorType }
+ )
+ }
+ const [, errorCallback, requestCommandName] = cachedRequest
logger.debug(
`${this.logPrefix()} << Command '${requestCommandName}' received error response payload: ${JSON.stringify(
errorResponse
)
}
// Respond
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const [responseCallback, , requestCommandName, requestPayload] = this.getCachedRequest(
- messageType,
- messageId
- )!
+ const cachedRequest = this.getCachedRequest(messageType, messageId)
+ if (cachedRequest == null) {
+ throw new OCPPError(
+ ErrorType.INTERNAL_ERROR,
+ `Cached request for response message id '${messageId}' is nullish`,
+ undefined,
+ commandPayload
+ )
+ }
+ const [responseCallback, , requestCommandName, requestPayload] = cachedRequest
logger.debug(
`${this.logPrefix()} << Command '${requestCommandName}' received response payload: ${JSON.stringify(
response
}
private initialize (options?: ChargingStationOptions): void {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const stationTemplate = this.getTemplateFromFile()!
+ const stationTemplate = this.getTemplateFromFile()
+ if (stationTemplate == null) {
+ const errorMsg = `Failed to read charging station template file ${this.templateFile}`
+ logger.error(`${this.logPrefix()} ${errorMsg}`)
+ throw new BaseError(errorMsg)
+ }
checkTemplate(stationTemplate, this.logPrefix(), this.templateFile)
this.configurationFile = join(
dirname(this.templateFile.replace('station-templates', 'configurations')),
this,
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 ?? 0) * getAmperageLimitationUnitDivider(this.stationInfo)).toString()
)
}
if (getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles) == null) {
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
for (const connectorId of evseStatus.connectors.keys()) {
- connectorsPhaseRotation.push(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- getPhaseRotationValue(connectorId, this.getNumberOfPhases())!
- )
+ const phaseRotation = getPhaseRotationValue(connectorId, this.getNumberOfPhases())
+ if (phaseRotation != null) {
+ connectorsPhaseRotation.push(phaseRotation)
+ }
}
}
} else {
for (const connectorId of this.connectors.keys()) {
- connectorsPhaseRotation.push(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- getPhaseRotationValue(connectorId, this.getNumberOfPhases())!
- )
+ const phaseRotation = getPhaseRotationValue(connectorId, this.getNumberOfPhases())
+ if (phaseRotation != null) {
+ connectorsPhaseRotation.push(phaseRotation)
+ }
}
}
addConfigurationKey(
case MessageType.CALL_ERROR_MESSAGE:
case MessageType.CALL_RESULT_MESSAGE:
if (this.requests.has(messageId)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ;[, errorCallback, requestCommandName] = this.getCachedRequest(messageType, messageId)!
- // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
- errorCallback(ocppError, false)
+ const cachedRequest = this.getCachedRequest(messageType, messageId)
+ if (cachedRequest != null) {
+ ;[, errorCallback, requestCommandName] = cachedRequest
+ // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
+ errorCallback(ocppError, false)
+ }
} else {
// Remove the request from the cache in case of error at response handling
this.requests.delete(messageId)
if (params.overwrite) {
chargingStation.ocppConfiguration.configurationKey[keyIndex] = {
...chargingStation.ocppConfiguration.configurationKey[keyIndex],
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- readonly: options.readonly!,
+ readonly: options.readonly ?? false,
reboot: options.reboot,
value,
visible: options.visible,
configurationKey.reboot = options.reboot
}
if (options.readonly != null && configurationKey.readonly !== options.readonly) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- configurationKey.readonly = options.readonly!
+ configurationKey.readonly = options.readonly
}
if (options.visible != null && configurationKey.visible !== options.visible) {
configurationKey.visible = options.visible
} else {
chargingStation.ocppConfiguration.configurationKey.push({
key: resolveKey(chargingStation, key),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- readonly: options.readonly!,
+ readonly: options.readonly ?? false,
reboot: options.reboot,
value,
visible: options.visible,
.map(chargingProfile => {
const chargingSchedule = getSingleChargingSchedule(chargingProfile)
if (chargingSchedule != null) {
- chargingSchedule.startSchedule = convertToDate(chargingSchedule.startSchedule)
+ chargingSchedule.startSchedule =
+ convertToDate(chargingSchedule.startSchedule) ?? new Date()
}
chargingProfile.validFrom = convertToDate(chargingProfile.validFrom)
chargingProfile.validTo = convertToDate(chargingProfile.validTo)
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.getChargingProfilesLimit: Charging profile id ${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) ?? new Date()
}
if (chargingSchedule.duration == null) {
logger.debug(
let recurringIntervalTranslated = false
let recurringInterval: Interval | undefined
switch (chargingProfile.recurrencyKind) {
- case RecurrencyKindType.DAILY:
+ case RecurrencyKindType.DAILY: {
+ const startSchedule = chargingSchedule.startSchedule ?? new Date()
recurringInterval = {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- end: addDays(chargingSchedule.startSchedule!, 1),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- start: chargingSchedule.startSchedule!,
+ end: addDays(startSchedule, 1),
+ start: startSchedule,
}
checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix)
if (
recurringIntervalTranslated = true
}
break
- case RecurrencyKindType.WEEKLY:
+ }
+ case RecurrencyKindType.WEEKLY: {
+ const startSchedule = chargingSchedule.startSchedule ?? new Date()
recurringInterval = {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- end: addWeeks(chargingSchedule.startSchedule!, 1),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- start: chargingSchedule.startSchedule!,
+ end: addWeeks(startSchedule, 1),
+ start: startSchedule,
}
checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix)
if (
recurringIntervalTranslated = true
}
break
+ }
default:
logger.error(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`${logPrefix} ${moduleName}.prepareRecurringChargingProfile: Recurring ${chargingProfile.recurrencyKind} charging profile id ${chargingProfileId} is not supported`
)
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- if (recurringIntervalTranslated && !isWithinInterval(currentDate, recurringInterval!)) {
+ if (
+ recurringIntervalTranslated &&
+ recurringInterval != null &&
+ !isWithinInterval(currentDate, recurringInterval)
+ ) {
logger.error(
`${logPrefix} ${moduleName}.prepareRecurringChargingProfile: Recurring ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
chargingProfile.recurrencyKind
} charging profile id ${chargingProfileId} recurrency time interval [${toDate(
- recurringInterval?.start as Date
+ recurringInterval.start as Date
).toISOString()}, ${toDate(
- recurringInterval?.end as Date
+ recurringInterval.end as Date
).toISOString()}] has not been properly translated to current date ${
isDate(currentDate) ? currentDate.toISOString() : currentDate.toString()
} `
}
private getRandomIdTag (hashId: string, file: string): string {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const idTags = this.getIdTags(file)!
+ const idTags = this.getIdTags(file) ?? []
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId)
this.idTagsCachesAddressableIndexes.set(
addressableKey,
Math.floor(secureRandom() * idTags.length)
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)!]
+ return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey) ?? 0]
}
private getRoundRobinIdTag (hashId: string, file: string): string {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const idTags = this.getIdTags(file)!
+ const idTags = this.getIdTags(file) ?? []
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId)
const idTagIndex = this.idTagsCachesAddressableIndexes.get(addressableKey) ?? 0
const idTag = idTags[idTagIndex]
): void {
if (this.isChargingStationConfigurationCacheable(chargingStationConfiguration)) {
this.set(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getChargingStationConfigurationKey(chargingStationConfiguration.configurationHash!),
+ this.getChargingStationConfigurationKey(
+ chargingStationConfiguration.configurationHash ?? ''
+ ),
chargingStationConfiguration
)
}
public setChargingStationTemplate (chargingStationTemplate: ChargingStationTemplate): void {
this.set(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getChargingStationTemplateKey(chargingStationTemplate.templateHash!),
+ this.getChargingStationTemplateKey(chargingStationTemplate.templateHash ?? ''),
chargingStationTemplate
)
}
): Promise<CommandResponse | void> {
if (this.commandHandlers.has(command)) {
this.cleanRequestPayload(command, requestPayload)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const commandHandler = this.commandHandlers.get(command)!
+ const commandHandler = this.commandHandlers.get(command)
+ if (commandHandler == null) {
+ throw new BaseError(`Unknown worker broadcast channel command: '${command}'`)
+ }
if (isAsyncFunction(commandHandler)) {
return await commandHandler(requestPayload)
}
requestPayload?: BroadcastChannelRequestPayload
): Promise<MeterValuesResponse> {
const connectorId = requestPayload?.connectorId
+ if (connectorId == null) {
+ throw new BaseError(
+ `${this.chargingStation.logPrefix()} ${moduleName}.handleMeterValues: Missing connectorId in request payload`
+ )
+ }
switch (this.chargingStation.stationInfo?.ocppVersion) {
case OCPPVersion.VERSION_16: {
const configuredMeterValueSampleInterval = getConfigurationKey(
this.chargingStation,
StandardParametersKey.MeterValueSampleInterval
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const transactionId = this.chargingStation.getConnectorStatus(connectorId!)?.transactionId
+ const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId
return await this.chargingStation.ocppRequestService.requestHandler<
MeterValuesRequest,
MeterValuesResponse
case OCPPVersion.VERSION_20:
case OCPPVersion.VERSION_201: {
const alignedDataInterval = OCPP20ServiceUtils.getAlignedDataInterval(this.chargingStation)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const evseId = this.chargingStation.getEvseIdByConnectorId(connectorId!)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const transactionId = this.chargingStation.getConnectorStatus(connectorId!)?.transactionId
+ const evseId = this.chargingStation.getEvseIdByConnectorId(connectorId)
+ const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId
return await this.chargingStation.ocppRequestService.requestHandler<
MeterValuesRequest,
MeterValuesResponse
return undefined
})
.finally(() => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.sendResponse([uuid, responsePayload!])
+ this.sendResponse([
+ uuid,
+ responsePayload ?? {
+ command,
+ hashId: this.chargingStation.stationInfo?.hashId,
+ status: ResponseStatus.FAILURE,
+ },
+ ])
})
}
}
responsesReceived: 1,
})
} else {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const responses = this.responses.get(uuid)!
- if (responses.responsesReceived < responses.responsesExpected) {
- ++responses.responsesReceived
- responses.responses.push(responsePayload)
- } else {
- logger.debug(
- `${this.uiService.logPrefix(moduleName, 'responseHandler')} Received response after all expected responses:`,
- { responsePayload, uuid }
- )
+ const responses = this.responses.get(uuid)
+ if (responses != null) {
+ if (responses.responsesReceived < responses.responsesExpected) {
+ ++responses.responsesReceived
+ responses.responses.push(responsePayload)
+ } else {
+ logger.debug(
+ `${this.uiService.logPrefix(moduleName, 'responseHandler')} Received response after all expected responses:`,
+ { responsePayload, uuid }
+ )
+ }
}
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const responses = this.responses.get(uuid)!
- if (responses.responsesReceived >= responses.responsesExpected) {
+ const responses = this.responses.get(uuid)
+ if (responses != null && responses.responsesReceived >= responses.responsesExpected) {
this.uiService.sendResponse(uuid, this.buildResponsePayload(uuid))
this.responses.delete(uuid)
this.uiService.deleteBroadcastChannelRequest(uuid)
chargingProfile.chargingSchedule.startSchedule
)
}
- if (chargingProfile.chargingSchedule.duration == null) {
+ if (
+ chargingProfile.chargingSchedule.duration == null &&
+ chargingProfile.chargingSchedule.startSchedule != null
+ ) {
logger.debug(
`${chargingStation.logPrefix()} ${moduleName}.composeCompositeSchedule: Charging profile id ${chargingProfile.chargingProfileId.toString()} has no duration defined and will be set to the maximum time allowed`
)
chargingProfile.chargingSchedule.duration = differenceInSeconds(
maxTime,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingProfile.chargingSchedule.startSchedule!
+ chargingProfile.chargingSchedule.startSchedule
)
}
if (
const logConfiguration = Configuration.getConfigurationSection<LogConfiguration>(
ConfigurationSection.log
)
+ const logFile = logConfiguration.file
+ if (logFile == null) {
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: log file not configured`
+ )
+ return OCPP16Constants.OCPP_RESPONSE_EMPTY
+ }
const logFiles = readdirSync(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- resolve((fileURLToPath(import.meta.url), '../', dirname(logConfiguration.file!)))
+ resolve((fileURLToPath(import.meta.url), '../', dirname(logFile)))
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- .filter(file => file.endsWith(extname(logConfiguration.file!)))
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- .map(file => join(dirname(logConfiguration.file!), file))
+ .filter(file => file.endsWith(extname(logFile)))
+ .map(file => join(dirname(logFile), file))
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const diagnosticsArchive = `${chargingStation.stationInfo?.chargingStationId}_logs.tar.gz`
create({ gzip: true }, logFiles).pipe(createWriteStream(diagnosticsArchive))
return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
}
if (
+ connectorId != null &&
!OCPP16ServiceUtils.isConnectorIdValid(
chargingStation,
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- connectorId!
+ connectorId
)
) {
return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
)
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- commandPayload.retrieveDate = convertToDate(commandPayload.retrieveDate)!
+ commandPayload.retrieveDate = convertToDate(commandPayload.retrieveDate) ?? new Date()
if (
chargingStation.stationInfo?.firmwareStatus === OCPP16FirmwareStatus.Downloading ||
chargingStation.stationInfo?.firmwareStatus === OCPP16FirmwareStatus.Downloaded ||
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)
- )!.reservationId,
+ )?.reservationId,
}),
...commandParams,
} as unknown as Request
idTag: chargingStation.getTransactionIdTag(commandParams.transactionId as number),
meterStop: energyActiveImportRegister,
timestamp: new Date(),
- ...(chargingStation.stationInfo?.transactionDataMeterValues === true && {
+ ...(chargingStation.stationInfo?.transactionDataMeterValues === true &&
+ connectorId != null && {
transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingStation.getConnectorStatus(connectorId!)!
- .transactionBeginMeterValue! as OCPP16MeterValue,
+ chargingStation.getConnectorStatus(connectorId)
+ ?.transactionBeginMeterValue as OCPP16MeterValue,
OCPP16ServiceUtils.buildTransactionEndMeterValue(
chargingStation,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- connectorId!,
+ connectorId,
energyActiveImportRegister
) as OCPP16MeterValue
),
}
}
if (authorizeConnectorId != null) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const authorizeConnectorStatus = chargingStation.getConnectorStatus(authorizeConnectorId)!
+ const authorizeConnectorStatus = chargingStation.getConnectorStatus(authorizeConnectorId)
+ if (authorizeConnectorStatus == null) {
+ return
+ }
if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
authorizeConnectorStatus.idTagAuthorized = true
logger.debug(
}#${connectorId.toString()} for idTag '${truncateId(requestPayload.idTag)}'`
)
if (chargingStation.stationInfo?.powerSharedByConnectors === true) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++chargingStation.powerDivider!
+ if (chargingStation.powerDivider != null) {
+ ++chargingStation.powerDivider
+ } else {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: powerDivider is undefined, cannot increment`
+ )
+ }
}
const configuredMeterValueSampleInterval = getConfigurationKey(
chargingStation,
} as OCPP16StatusNotificationRequest)
}
if (chargingStation.stationInfo?.powerSharedByConnectors === true) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingStation.powerDivider!--
+ if (chargingStation.powerDivider != null && chargingStation.powerDivider > 0) {
+ --chargingStation.powerDivider
+ } else {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStopTransaction: powerDivider is ${
+ chargingStation.powerDivider?.toString() ?? 'undefined'
+ }, cannot decrement`
+ )
+ }
}
const transactionConnectorStatus = chargingStation.getConnectorStatus(transactionConnectorId)
resetConnectorStatus(transactionConnectorStatus)
for (const connectorId of connectorIds) {
let response: OCPP16ChangeAvailabilityResponse =
OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
+ if (connectorStatus == null) {
+ continue
+ }
if (connectorStatus.transactionStarted === true) {
response = OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
}
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.setChargingProfile: Trying to set a charging profile on connector id ${connectorId.toString()} with an uninitialized charging profiles array attribute, applying deferred initialization`
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingStation.getConnectorStatus(connectorId)!.chargingProfiles = []
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
+ if (connectorStatus != null) {
+ connectorStatus.chargingProfiles = []
+ }
}
if (!Array.isArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) {
logger.warn(
chargingSchedule: OCPP16ChargingSchedule,
compositeInterval: Interval
): OCPP16ChargingSchedule | undefined => {
+ if (chargingSchedule.startSchedule == null || chargingSchedule.duration == null) {
+ return undefined
+ }
const chargingScheduleInterval: Interval = {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- start: chargingSchedule.startSchedule!,
+ end: addSeconds(chargingSchedule.startSchedule, chargingSchedule.duration),
+ start: chargingSchedule.startSchedule,
}
if (areIntervalsOverlapping(chargingScheduleInterval, compositeInterval)) {
chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod)
) => {
if (response.status === RequestStartStopStatusEnumType.Accepted) {
const connectorId = chargingStation.getConnectorIdByTransactionId(response.transactionId)
- if (connectorId != null) {
+ if (connectorId != null && response.transactionId != null) {
const connectorStatus = chargingStation.getConnectorStatus(connectorId)
const startedMeterValues =
connectorStatus != null
OCPP20TransactionEventEnumType.Started,
OCPP20TriggerReasonEnumType.RemoteStart,
connectorId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- response.transactionId!,
+ response.transactionId,
startedMeterValues.length > 0 ? { meterValue: startedMeterValues } : undefined
).catch((error: unknown) => {
logger.error(
)
if (maxChainSizeKey?.value != null) {
const maxChainSize = parseInt(maxChainSizeKey.value, 10)
- if (!isNaN(maxChainSize) && maxChainSize > 0) {
+ if (!Number.isNaN(maxChainSize) && maxChainSize > 0) {
const chainByteSize = Buffer.byteLength(certificateChain, 'utf8')
if (chainByteSize > maxChainSize) {
logger.warn(
idTokenString: string
): boolean {
try {
+ const idTagsFile =
+ chargingStation.stationInfo != null ? getIdTagsFile(chargingStation.stationInfo) : undefined
return (
chargingStation.hasIdTags() &&
- chargingStation.idTagsCache
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- .getIdTags(getIdTagsFile(chargingStation.stationInfo!)!)
- ?.includes(idTokenString) === true
+ idTagsFile != null &&
+ chargingStation.idTagsCache.getIdTags(idTagsFile)?.includes(idTokenString) === true
)
} catch (error) {
logger.error(
) {
try {
this.validateIncomingRequestPayload(chargingStation, commandName, commandPayload)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const incomingRequestHandler = this.incomingRequestHandlers.get(commandName)!
+ const incomingRequestHandler = this.incomingRequestHandlers.get(commandName)
+ if (incomingRequestHandler == null) {
+ throw new OCPPError(
+ ErrorType.NOT_IMPLEMENTED,
+ `${commandName} incoming request handler not found`,
+ commandName,
+ commandPayload
+ )
+ }
if (isAsyncFunction(incomingRequestHandler)) {
response = (await incomingRequestHandler(chargingStation, commandPayload)) as ResType
} else {
logger.debug(
`${chargingStation.logPrefix()} ${this.moduleName}.responseHandler: Handling '${commandName}' response`
)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const responseHandler = this.responseHandlers.get(commandName)!
+ const responseHandler = this.responseHandlers.get(commandName)
+ if (responseHandler == null) {
+ throw new OCPPError(
+ ErrorType.NOT_IMPLEMENTED,
+ `${commandName} response handler not found`,
+ commandName,
+ payload
+ )
+ }
if (isAsyncFunction(responseHandler)) {
await responseHandler(chargingStation, payload, requestPayload)
} else {
}
const isIdTagLocalAuthorized = (chargingStation: ChargingStation, idTag: string): boolean => {
+ const idTagsFile =
+ chargingStation.stationInfo != null ? getIdTagsFile(chargingStation.stationInfo) : undefined
return (
chargingStation.hasIdTags() &&
- isNotEmptyString(
- chargingStation.idTagsCache
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- .getIdTags(getIdTagsFile(chargingStation.stationInfo!)!)
- ?.find(tag => tag === idTag)
- )
+ idTagsFile != null &&
+ isNotEmptyString(chargingStation.idTagsCache.getIdTags(idTagsFile)?.find(tag => tag === idTag))
)
}
connectorId: number,
idTag: string
): Promise<boolean> => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingStation.getConnectorStatus(connectorId)!.authorizeIdTag = idTag
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
+ if (connectorStatus != null) {
+ connectorStatus.authorizeIdTag = idTag
+ }
switch (chargingStation.stationInfo?.ocppVersion) {
case OCPPVersion.VERSION_16:
return (
return max(
min(
(!Number.isNaN(parsedValue) ? parsedValue : Number.POSITIVE_INFINITY) *
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- options.unitMultiplier!,
+ (options.unitMultiplier ?? 1),
maxLimit
),
minLimit
)
}
return (
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- (!Number.isNaN(parsedValue) ? parsedValue : options.fallbackValue!) * options.unitMultiplier!
+ (!Number.isNaN(parsedValue) ? parsedValue : (options.fallbackValue ?? 0)) *
+ (options.unitMultiplier ?? 1)
)
}
}
// Call the request handler to build the response payload
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const requestHandler = this.requestHandlers.get(command)!
+ const requestHandler = this.requestHandlers.get(command)
+ if (requestHandler == null) {
+ throw new BaseError(`'${command}' request handler not found`)
+ }
if (isAsyncFunction(requestHandler)) {
responsePayload = await requestHandler(uuid, command, requestPayload)
} else {
messageType: MessageType
): void {
switch (messageType) {
- case MessageType.CALL_ERROR_MESSAGE:
- if (
- this.statistics.statisticsData.has(command) &&
- this.statistics.statisticsData.get(command)?.errorCount != null
- ) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++this.statistics.statisticsData.get(command)!.errorCount!
+ case MessageType.CALL_ERROR_MESSAGE: {
+ const commandStatisticsData = this.statistics.statisticsData.get(command)
+ if (commandStatisticsData?.errorCount != null) {
+ ++commandStatisticsData.errorCount
} else {
this.statistics.statisticsData.set(command, {
- ...this.statistics.statisticsData.get(command),
+ ...commandStatisticsData,
errorCount: 1,
})
}
break
- case MessageType.CALL_MESSAGE:
- if (
- this.statistics.statisticsData.has(command) &&
- this.statistics.statisticsData.get(command)?.requestCount != null
- ) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++this.statistics.statisticsData.get(command)!.requestCount!
+ }
+ case MessageType.CALL_MESSAGE: {
+ const commandStatisticsData = this.statistics.statisticsData.get(command)
+ if (commandStatisticsData?.requestCount != null) {
+ ++commandStatisticsData.requestCount
} else {
this.statistics.statisticsData.set(command, {
- ...this.statistics.statisticsData.get(command),
+ ...commandStatisticsData,
requestCount: 1,
})
}
break
- case MessageType.CALL_RESULT_MESSAGE:
- if (
- this.statistics.statisticsData.has(command) &&
- this.statistics.statisticsData.get(command)?.responseCount != null
- ) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++this.statistics.statisticsData.get(command)!.responseCount!
+ }
+ case MessageType.CALL_RESULT_MESSAGE: {
+ const commandStatisticsData = this.statistics.statisticsData.get(command)
+ if (commandStatisticsData?.responseCount != null) {
+ ++commandStatisticsData.responseCount
} else {
this.statistics.statisticsData.set(command, {
- ...this.statistics.statisticsData.get(command),
+ ...commandStatisticsData,
responseCount: 1,
})
}
break
+ }
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
logger.error(`${this.logPrefix()} wrong message type ${messageType}`)
if (!this.statistics.statisticsData.has(entry.name)) {
this.statistics.statisticsData.set(entry.name, {})
}
- // Update current statistics
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.timeMeasurementCount =
- (this.statistics.statisticsData.get(entry.name)?.timeMeasurementCount ?? 0) + 1
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.currentTimeMeasurement = entry.duration
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.minTimeMeasurement = min(
- entry.duration,
- this.statistics.statisticsData.get(entry.name)?.minTimeMeasurement ?? Number.POSITIVE_INFINITY
- )
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.maxTimeMeasurement = max(
- entry.duration,
- this.statistics.statisticsData.get(entry.name)?.maxTimeMeasurement ?? Number.NEGATIVE_INFINITY
- )
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.totalTimeMeasurement =
- (this.statistics.statisticsData.get(entry.name)?.totalTimeMeasurement ?? 0) + entry.duration
- if (
- !(
- this.statistics.statisticsData.get(entry.name)?.measurementTimeSeries instanceof
- CircularBuffer
+ const entryStatisticsData = this.statistics.statisticsData.get(entry.name)
+ if (entryStatisticsData != null) {
+ // Update current statistics
+ entryStatisticsData.timeMeasurementCount = (entryStatisticsData.timeMeasurementCount ?? 0) + 1
+ entryStatisticsData.currentTimeMeasurement = entry.duration
+ entryStatisticsData.minTimeMeasurement = min(
+ entry.duration,
+ entryStatisticsData.minTimeMeasurement ?? Number.POSITIVE_INFINITY
)
- ) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.measurementTimeSeries =
- new CircularBuffer<TimestampedData>(
+ entryStatisticsData.maxTimeMeasurement = max(
+ entry.duration,
+ entryStatisticsData.maxTimeMeasurement ?? Number.NEGATIVE_INFINITY
+ )
+ entryStatisticsData.totalTimeMeasurement =
+ (entryStatisticsData.totalTimeMeasurement ?? 0) + entry.duration
+ if (!(entryStatisticsData.measurementTimeSeries instanceof CircularBuffer)) {
+ entryStatisticsData.measurementTimeSeries = new CircularBuffer<TimestampedData>(
Array<TimestampedData>,
Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY
)
+ }
+ entryStatisticsData.measurementTimeSeries.push({
+ timestamp: entry.startTime,
+ value: entry.duration,
+ })
+ const timeMeasurementValues = extractTimeSeriesValues(
+ entryStatisticsData.measurementTimeSeries
+ )
+ entryStatisticsData.avgTimeMeasurement = average(timeMeasurementValues)
+ entryStatisticsData.medTimeMeasurement = median(timeMeasurementValues)
+ entryStatisticsData.ninetyFiveThPercentileTimeMeasurement = percentile(
+ timeMeasurementValues,
+ 95
+ )
+ entryStatisticsData.stdTimeMeasurement = std(
+ timeMeasurementValues,
+ entryStatisticsData.avgTimeMeasurement
+ )
}
- this.statistics.statisticsData.get(entry.name)?.measurementTimeSeries?.push({
- timestamp: entry.startTime,
- value: entry.duration,
- })
- const timeMeasurementValues = extractTimeSeriesValues(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!
- .measurementTimeSeries as CircularBuffer<TimestampedData>
- )
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement =
- average(timeMeasurementValues)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.medTimeMeasurement =
- median(timeMeasurementValues)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.ninetyFiveThPercentileTimeMeasurement =
- percentile(timeMeasurementValues, 95)
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.stdTimeMeasurement = std(
- timeMeasurementValues,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement
- )
this.statistics.updatedAt = new Date()
if (
Configuration.getConfigurationSection<StorageConfiguration>(
ConfigurationSection.log
)
const logStatisticsInterval =
- logConfiguration.enabled === true
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- logConfiguration.statisticsInterval!
- : 0
+ logConfiguration.enabled === true ? (logConfiguration.statisticsInterval ?? 0) : 0
if (logStatisticsInterval > 0 && this.displayInterval == null) {
this.displayInterval = setInterval(() => {
this.logStatistics()
}
private static getAsyncLock (type: AsyncLockType): AsyncLock {
- if (!AsyncLock.asyncLocks.has(type)) {
- AsyncLock.asyncLocks.set(type, new AsyncLock())
+ let asyncLock = AsyncLock.asyncLocks.get(type)
+ if (asyncLock == null) {
+ asyncLock = new AsyncLock()
+ AsyncLock.asyncLocks.set(type, asyncLock)
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return AsyncLock.asyncLocks.get(type)!
+ return asyncLock
}
private static release (type: AsyncLockType): void {
}
public static workerPoolInUse (): boolean {
- return [WorkerProcessType.dynamicPool, WorkerProcessType.fixedPool].includes(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- Configuration.getConfigurationSection<WorkerConfiguration>(ConfigurationSection.worker)
- .processType!
+ const processType = Configuration.getConfigurationSection<WorkerConfiguration>(
+ ConfigurationSection.worker
+ ).processType
+ return (
+ processType != null &&
+ [WorkerProcessType.dynamicPool, WorkerProcessType.fixedPool].includes(processType)
)
}
...(deprecatedWorkerConfiguration as Partial<WorkerConfiguration>),
...(has(ConfigurationSection.worker, configData) && configData?.worker),
}
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- checkWorkerProcessType(workerConfiguration.processType!)
+ if (workerConfiguration.processType != null) {
+ checkWorkerProcessType(workerConfiguration.processType)
+ }
checkWorkerElementsPerWorker(workerConfiguration.elementsPerWorker)
return workerConfiguration
}
}
const logFormat = format.combine(
format.splat(),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)()
+ (format[(logConfiguration.format ?? 'simple') as keyof FormatWrap] as FormatWrap)()
)
loggerInstance = createLogger({
format: logFormat,
import {
type ChargingStationData,
+ type ChargingStationInfo,
+ type ChargingStationOcppConfiguration,
type ChargingStationWorkerMessage,
ChargingStationWorkerMessageEvents,
type Statistics,
bootNotificationResponse: chargingStation.bootNotificationResponse,
connectors: buildConnectorEntries(chargingStation),
evses: buildEvseEntries(chargingStation),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ocppConfiguration: chargingStation.ocppConfiguration!,
+ ocppConfiguration:
+ chargingStation.ocppConfiguration ?? ({} as ChargingStationOcppConfiguration),
started: chargingStation.started,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- stationInfo: chargingStation.stationInfo!,
+ stationInfo: chargingStation.stationInfo ?? ({} as ChargingStationInfo),
supervisionUrl: chargingStation.wsConnectionUrl.href,
timestamp: Date.now(),
wsState: chargingStation.wsConnection?.readyState,
import { SHARE_ENV, Worker } from 'node:worker_threads'
import { WorkerAbstract } from './WorkerAbstract.js'
-import { EMPTY_FUNCTION, workerSetVersion } from './WorkerConstants.js'
+import { DEFAULT_ELEMENTS_PER_WORKER, EMPTY_FUNCTION, workerSetVersion } from './WorkerConstants.js'
import {
type SetInfo,
type UUIDv4,
(accumulator, workerSetElement) => accumulator + workerSetElement.numberOfWorkerElements,
0
),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- elementsPerWorker: this.maxElementsPerWorker!,
+ elementsPerWorker: this.maxElementsPerWorker ?? DEFAULT_ELEMENTS_PER_WORKER,
size: this.size,
started: this.started,
type: 'set',
worker.on('message', (message: WorkerMessage<R>) => {
const { data, event, uuid } = message
if (this.promiseResponseMap.has(uuid)) {
+ const responseWrapper = this.promiseResponseMap.get(uuid)
+ if (responseWrapper == null) {
+ return
+ }
let error: Error
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const { reject, resolve, workerSetElement } = this.promiseResponseMap.get(uuid)!
+ const { reject, resolve, workerSetElement } = responseWrapper
switch (event) {
case WorkerMessageEvents.addedWorkerElement:
++workerSetElement.numberOfWorkerElements
private async getWorkerSetElement (): Promise<WorkerSetElement> {
let chosenWorkerSetElement: undefined | WorkerSetElement
for (const workerSetElement of this.workerSet) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- if (workerSetElement.numberOfWorkerElements < this.workerOptions.elementsPerWorker!) {
+ if (
+ workerSetElement.numberOfWorkerElements <
+ (this.workerOptions.elementsPerWorker ?? DEFAULT_ELEMENTS_PER_WORKER)
+ ) {
chosenWorkerSetElement = workerSetElement
break
}