public getConnectorMaximumAvailablePower (connectorId: number): number {
let connectorAmperageLimitationPowerLimit: number | undefined
+ const amperageLimitation = this.getAmperageLimitation()
if (
- this.getAmperageLimitation() != null &&
+ amperageLimitation != null &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getAmperageLimitation()! < this.stationInfo!.maximumAmperage!
+ amperageLimitation < this.stationInfo!.maximumAmperage!
) {
connectorAmperageLimitationPowerLimit =
(this.stationInfo?.currentOutType === CurrentType.AC
this.getNumberOfPhases(),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.stationInfo.voltageOut!,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getAmperageLimitation()! *
+ amperageLimitation *
(this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors())
)
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- DCElectricUtils.power(this.stationInfo!.voltageOut!, this.getAmperageLimitation()!)) /
+ DCElectricUtils.power(this.stationInfo!.voltageOut!, amperageLimitation)) /
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.powerDivider!
}
connectorId: number,
reason?: StopTransactionReason
): Promise<StopTransactionResponse> {
- const transactionId = this.getConnectorStatus(connectorId)?.transactionId
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const transactionId = this.getConnectorStatus(connectorId)!.transactionId!
if (
this.stationInfo?.beginEndMeterValues === true &&
this.stationInfo.ocppStrictCompliance === true &&
const transactionEndMeterValue = buildTransactionEndMeterValue(
this,
connectorId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getEnergyActiveImportRegisterByTransactionId(transactionId!)
+ this.getEnergyActiveImportRegisterByTransactionId(transactionId)
)
await this.ocppRequestService.requestHandler<MeterValuesRequest, MeterValuesResponse>(
this,
StopTransactionResponse
>(this, RequestCommand.STOP_TRANSACTION, {
transactionId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId!, true),
+ meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true),
...(reason != null && { reason })
})
}
// Priority:
// 1. charging station info from template
// 2. charging station info from configuration file
- if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return { ...defaultStationInfo, ...stationInfoFromFile! }
+ if (
+ stationInfoFromFile != null &&
+ stationInfoFromFile.templateHash === stationInfoFromTemplate.templateHash
+ ) {
+ return { ...defaultStationInfo, ...stationInfoFromFile }
}
stationInfoFromFile != null &&
propagateSerialNumber(
isNotEmptyString(this.stationInfo.firmwareVersion) &&
isNotEmptyString(this.stationInfo.firmwareVersionPattern)
) {
- const patternGroup: number | undefined =
+ const patternGroup =
this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
this.stationInfo.firmwareVersion?.split('.').length
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (this.stationInfo.enableStatistics === true) {
this.performanceStatistics = PerformanceStatistics.getInstance(
this.stationInfo.hashId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.stationInfo.chargingStationId!,
+ this.stationInfo.chargingStationId,
this.configuredSupervisionUrl
)
}
- this.bootNotificationRequest = createBootNotificationRequest(this.stationInfo)
+ const bootNotificationRequest = createBootNotificationRequest(this.stationInfo)
+ if (bootNotificationRequest == null) {
+ const errorMsg = 'Error while creating boot notification request'
+ logger.error(`${this.logPrefix()} ${errorMsg}`)
+ throw new BaseError(errorMsg)
+ }
+ this.bootNotificationRequest = bootNotificationRequest
this.powerDivider = this.getPowerDivider()
// OCPP configuration
this.ocppConfiguration = this.getOcppConfiguration()
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,
if (!existsSync(dirname(this.configurationFile))) {
mkdirSync(dirname(this.configurationFile), { recursive: true })
}
+ const configurationFromFile = this.getConfigurationFromFile()
let configurationData: ChargingStationConfiguration =
- this.getConfigurationFromFile() != null
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()!)
+ configurationFromFile != null
+ ? cloneObject<ChargingStationConfiguration>(configurationFromFile)
: {}
if (this.stationInfo?.stationInfoPersistentConfiguration === true) {
configurationData.stationInfo = this.stationInfo
export const createBootNotificationRequest = (
stationInfo: ChargingStationInfo,
bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp
-): BootNotificationRequest => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const ocppVersion = stationInfo.ocppVersion!
+): BootNotificationRequest | undefined => {
+ const ocppVersion = stationInfo.ocppVersion
switch (ocppVersion) {
case OCPPVersion.VERSION_16:
return {
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) {
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
}
- if (chargingSchedule.startSchedule != null && !isDate(chargingSchedule.startSchedule)) {
+ if (!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)!
}
- if (chargingSchedule.startSchedule != null && chargingSchedule.duration == null) {
+ if (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`
)
// Check if the charging profile is active
if (
isWithinInterval(currentDate, {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- start: chargingSchedule.startSchedule!,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!)
+ start: chargingSchedule.startSchedule,
+ end: addSeconds(chargingSchedule.startSchedule, chargingSchedule.duration)
})
) {
if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) {
// Find the right schedule period
if (
isAfter(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- addSeconds(chargingSchedule.startSchedule!, chargingSchedulePeriod.startPeriod),
+ addSeconds(chargingSchedule.startSchedule, chargingSchedulePeriod.startPeriod),
currentDate
)
) {
(index < chargingSchedule.chargingSchedulePeriod.length - 1 &&
differenceInSeconds(
addSeconds(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingSchedule.startSchedule!,
+ chargingSchedule.startSchedule,
chargingSchedule.chargingSchedulePeriod[index + 1].startPeriod
),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- chargingSchedule.startSchedule!
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ) > chargingSchedule.duration!)
+ chargingSchedule.startSchedule
+ ) > chargingSchedule.duration)
) {
const result: ChargingProfilesLimit = {
limit: previousChargingSchedulePeriod.limit,
let previousCompositeSchedule: OCPP16ChargingSchedule | undefined
let compositeSchedule: OCPP16ChargingSchedule | undefined
for (const chargingProfile of chargingProfiles) {
- if (
- chargingProfile.chargingSchedule.startSchedule == null &&
- connectorStatus.transactionStarted === true
- ) {
+ if (chargingProfile.chargingSchedule.startSchedule == null) {
logger.debug(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
chargingProfile.chargingProfileId
// OCPP specifies that if startSchedule is not defined, it should be relative to start of the connector transaction
chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
}
- if (
- chargingProfile.chargingSchedule.startSchedule != null &&
- !isDate(chargingProfile.chargingSchedule.startSchedule)
- ) {
+ if (!isDate(chargingProfile.chargingSchedule.startSchedule)) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
chargingProfile.chargingProfileId
chargingProfile.chargingSchedule.startSchedule
)!
}
- if (
- chargingProfile.chargingSchedule.startSchedule != null &&
- chargingProfile.chargingSchedule.duration == null
- ) {
+ if (chargingProfile.chargingSchedule.duration == null) {
logger.debug(
`${chargingStation.logPrefix()} ${moduleName}.handleRequestGetCompositeSchedule: Charging profile id ${
chargingProfile.chargingProfileId
}
let cpReplaced = false
if (isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const [index, chargingProfile] of chargingStation
- .getConnectorStatus(connectorId)
- ?.chargingProfiles?.entries() ?? []) {
+ .getConnectorStatus(connectorId)!
+ .chargingProfiles!.entries()) {
if (
chargingProfile.chargingProfileId === cp.chargingProfileId ||
(chargingProfile.stackLevel === cp.stackLevel &&
type AuthorizeResponse,
ChargePointErrorCode,
ChargingStationEvents,
- type ConnectorStatus,
type ConnectorStatusEnum,
CurrentType,
ErrorType,
}
if (chargingStation.getLocalAuthListEnabled() && isIdTagLocalAuthorized(chargingStation, idTag)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const connectorStatus: ConnectorStatus = chargingStation.getConnectorStatus(connectorId)!
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)!
connectorStatus.localAuthorizeIdTag = idTag
connectorStatus.idTagLocalAuthorized = true
return true
import { secondsToMilliseconds } from 'date-fns'
+import { BaseError } from '../exception/index.js'
import {
ConfigurationSection,
type IncomingRequestCommand,
private readonly statistics: Statistics
private displayInterval?: NodeJS.Timeout
- private constructor (objId: string | undefined, objName: string | undefined, uri: URL) {
- this.objId = objId ?? 'Object id not specified'
- this.objName = objName ?? 'Object name not specified'
+ private constructor (objId: string, objName: string, uri: URL) {
+ this.objId = objId
+ this.objName = objName
this.initializePerformanceObserver()
this.statistics = {
id: this.objId,
}
public static getInstance (
- objId: string,
- objName: string,
- uri: URL
+ objId: string | undefined,
+ objName: string | undefined,
+ uri: URL | undefined
): PerformanceStatistics | undefined {
+ const logPfx = logPrefix(' Performance statistics')
+ if (objId == null) {
+ const errMsg = 'Cannot get performance statistics instance without specifying object id'
+ logger.error(`${logPfx} ${errMsg}`)
+ throw new BaseError(errMsg)
+ }
+ if (objName == null) {
+ const errMsg = 'Cannot get performance statistics instance without specifying object name'
+ logger.error(`${logPfx} ${errMsg}`)
+ throw new BaseError(errMsg)
+ }
+ if (uri == null) {
+ const errMsg = 'Cannot get performance statistics instance without specifying object uri'
+ logger.error(`${logPfx} ${errMsg}`)
+ throw new BaseError(errMsg)
+ }
if (!PerformanceStatistics.instances.has(objId)) {
PerformanceStatistics.instances.set(objId, new PerformanceStatistics(objId, objName, uri))
}