isNotEmptyString(
chargingStation.idTagsCache
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- .getIdTags(getIdTagsFile(chargingStation.stationInfo)!)
+ .getIdTags(getIdTagsFile(chargingStation.stationInfo!)!)
?.find((tag) => tag === idTag)
)
)
idTag
}
)
- )?.idTagInfo?.status === AuthorizationStatus.ACCEPTED
+ ).idTagInfo.status === AuthorizationStatus.ACCEPTED
)
}
}
if (!transitionAllowed) {
logger.warn(
- `${chargingStation.logPrefix()} OCPP ${chargingStation.stationInfo
- ?.ocppVersion} connector id ${connectorId} status transition from '${
+ `${chargingStation.logPrefix()} OCPP ${
+ chargingStation.stationInfo.ocppVersion
+ } connector id ${connectorId} status transition from '${
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
chargingStation.getConnectorStatus(connectorId)!.status
}' to '${status}' is not allowed`
if (
chargingStation.getNumberOfPhases() !== 3 ||
(chargingStation.getNumberOfPhases() === 3 &&
- chargingStation.stationInfo?.mainVoltageMeterValues === true)
+ chargingStation.stationInfo.mainVoltageMeterValues === true)
) {
meterValue.sampledValue.push(
buildSampledValue(voltageSampledValueTemplate, voltageMeasurandValue)
phaseLineToNeutralValue as MeterValuePhase
)
)
- if (chargingStation.stationInfo?.phaseLineToLineVoltageMeterValues === true) {
+ if (chargingStation.stationInfo.phaseLineToLineVoltageMeterValues === true) {
const phaseLineToLineValue = `L${phase}-L${
(phase + 1) % chargingStation.getNumberOfPhases() !== 0
? (phase + 1) % chargingStation.getNumberOfPhases()
}
if (powerSampledValueTemplate != null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- checkMeasurandPowerDivider(chargingStation, powerSampledValueTemplate.measurand!)
+ checkMeasurandPowerDivider(chargingStation, powerSampledValueTemplate.measurand)
const errMsg = `MeterValues measurand ${
powerSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
- }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
+ }: Unknown ${chargingStation.stationInfo.currentOutType} currentOutType in template file ${
chargingStation.templateFile
}, cannot calculate ${
powerSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
} measurand value`
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const powerMeasurandValues: MeasurandValues = {} as MeasurandValues
- const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1
+ const unitDivider = powerSampledValueTemplate.unit === MeterValueUnit.KILO_WATT ? 1000 : 1
const connectorMaximumAvailablePower =
chargingStation.getConnectorMaximumAvailablePower(connectorId)
const connectorMaximumPower = Math.round(connectorMaximumAvailablePower)
const connectorMinimumPowerPerPhase = Math.round(
connectorMinimumPower / chargingStation.getNumberOfPhases()
)
- switch (chargingStation.stationInfo?.currentOutType) {
+ switch (chargingStation.stationInfo.currentOutType) {
case CurrentType.AC:
if (chargingStation.getNumberOfPhases() === 3) {
const defaultFluctuatedPowerPerPhase = isNotEmptyString(
connectorMinimumPower / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPower / unitDivider
}
) / chargingStation.getNumberOfPhases(),
connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPowerPerPhase / unitDivider
}
),
connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPowerPerPhase / unitDivider
}
),
connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPowerPerPhase / unitDivider
}
),
connectorMinimumPower / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPower / unitDivider
}
),
connectorMinimumPower / unitDivider,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumPower / unitDivider
}
),
}
if (currentSampledValueTemplate != null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- checkMeasurandPowerDivider(chargingStation, currentSampledValueTemplate.measurand!)
+ checkMeasurandPowerDivider(chargingStation, currentSampledValueTemplate.measurand)
const errMsg = `MeterValues measurand ${
currentSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
- }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${
+ }: Unknown ${chargingStation.stationInfo.currentOutType} currentOutType in template file ${
chargingStation.templateFile
}, cannot calculate ${
currentSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
chargingStation.getConnectorMaximumAvailablePower(connectorId)
const connectorMinimumAmperage = currentSampledValueTemplate.minimumValue ?? 0
let connectorMaximumAmperage: number
- switch (chargingStation.stationInfo?.currentOutType) {
+ switch (chargingStation.stationInfo.currentOutType) {
case CurrentType.AC:
connectorMaximumAmperage = ACElectricUtils.amperagePerPhaseFromPower(
chargingStation.getNumberOfPhases(),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
connectorMinimumAmperage,
{
limitationEnabled:
- chargingStation.stationInfo?.customValueLimitationMeterValues,
+ chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumAmperage
}
),
energySampledValueTemplate = getSampledValueTemplate(chargingStation, connectorId)
if (energySampledValueTemplate != null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- checkMeasurandPowerDivider(chargingStation, energySampledValueTemplate.measurand!)
+ checkMeasurandPowerDivider(chargingStation, energySampledValueTemplate.measurand)
const unitDivider =
- energySampledValueTemplate?.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
+ energySampledValueTemplate.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
const connectorMaximumAvailablePower =
chargingStation.getConnectorMaximumAvailablePower(connectorId)
const connectorMaximumEnergyRounded = roundTo(
connectorMaximumEnergyRounded,
connectorMinimumEnergyRounded,
{
- limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues,
+ limitationEnabled: chargingStation.stationInfo.customValueLimitationMeterValues,
fallbackValue: connectorMinimumEnergyRounded,
unitMultiplier: unitDivider
}
export const buildTransactionEndMeterValue = (
chargingStation: ChargingStation,
connectorId: number,
- meterStop: number
+ meterStop: number | undefined
): MeterValue => {
let meterValue: MeterValue
let sampledValueTemplate: SampledValueTemplate | undefined
const checkMeasurandPowerDivider = (
chargingStation: ChargingStation,
- measurandType: MeterValueMeasurand
+ measurandType: MeterValueMeasurand | undefined
): void => {
if (chargingStation.powerDivider == null) {
const errMsg = `MeterValues measurand ${
}: powerDivider is undefined`
logger.error(`${chargingStation.logPrefix()} ${errMsg}`)
throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, RequestCommand.METER_VALUES)
- } else if (chargingStation?.powerDivider <= 0) {
+ } else if (chargingStation.powerDivider <= 0) {
const errMsg = `MeterValues measurand ${
measurandType ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
}: powerDivider have zero or below value ${chargingStation.powerDivider}`
...options
}
const parsedValue = parseInt(value ?? '')
- if (options?.limitationEnabled === true) {
+ if (options.limitationEnabled === true) {
return max(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
min((!isNaN(parsedValue) ? parsedValue : Infinity) * options.unitMultiplier!, maxLimit),
context?: MeterValueContext,
phase?: MeterValuePhase
): SampledValue => {
- const sampledValueContext = context ?? sampledValueTemplate?.context
+ const sampledValueContext = context ?? sampledValueTemplate.context
const sampledValueLocation =
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- sampledValueTemplate?.location ?? getMeasurandDefaultLocation(sampledValueTemplate.measurand!)
- const sampledValuePhase = phase ?? sampledValueTemplate?.phase
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+ sampledValueTemplate.location ?? getMeasurandDefaultLocation(sampledValueTemplate.measurand!)
+ const sampledValuePhase = phase ?? sampledValueTemplate.phase
return {
...(sampledValueTemplate.unit != null && {
unit: sampledValueTemplate.unit
measurand: sampledValueTemplate.measurand
}),
...(sampledValueLocation != null && { location: sampledValueLocation }),
- ...(value != null && { value: value.toString() }),
+ ...{ value: value.toString() },
...(sampledValuePhase != null && { phase: sampledValuePhase })
- } as SampledValue
+ } satisfies SampledValue
}
const getMeasurandDefaultLocation = (
isRequestCommand &&
chargingStation.stationInfo?.commandsSupport?.outgoingCommands?.[command] != null
) {
- return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command]
+ return chargingStation.stationInfo.commandsSupport.outgoingCommands[command]
}
logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`)
return false
return true
} else if (
isIncomingRequestCommand &&
- chargingStation.stationInfo?.commandsSupport?.incomingCommands?.[command] != null
+ chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] != null
) {
- return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command]
+ return chargingStation.stationInfo.commandsSupport.incomingCommands[command]
}
logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`)
return false
isMessageTrigger &&
chargingStation.stationInfo?.messageTriggerSupport?.[messageTrigger] != null
) {
- return chargingStation.stationInfo?.messageTriggerSupport[messageTrigger]
+ return chargingStation.stationInfo.messageTriggerSupport[messageTrigger]
}
logger.error(
`${chargingStation.logPrefix()} Unknown incoming OCPP message trigger '${messageTrigger}'`
if (isDate(obj![key])) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
(obj![key] as string) = (obj![key] as Date).toISOString()
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
- } else if (obj![key] !== null && typeof obj![key] === 'object') {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-condition
+ } else if (typeof obj![key] === 'object' && obj![key] !== null) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
OCPPServiceUtils.convertDateToISOString<T>(obj![key] as T)
}