}
private getConfiguredSupervisionUrl (): URL {
- let configuredSupervisionUrl: string
+ let configuredSupervisionUrl: string | undefined
const supervisionUrls = this.stationInfo?.supervisionUrls ?? Configuration.getSupervisionUrls()
if (isNotEmptyArray(supervisionUrls)) {
let configuredSupervisionUrlIndex: number
break
}
configuredSupervisionUrl = supervisionUrls[configuredSupervisionUrlIndex]
- } else {
+ } else if (typeof supervisionUrls === 'string') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
configuredSupervisionUrl = supervisionUrls!
}
stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate)
createSerialNumber(stationTemplate, stationInfo)
stationInfo.voltageOut = this.getVoltageOut(stationInfo)
- if (isNotEmptyArray(stationTemplate.power)) {
+ if (isNotEmptyArray<number>(stationTemplate.power)) {
const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length)
stationInfo.maximumPower =
stationTemplate.powerUnit === PowerUnits.KILO_WATT
? stationTemplate.power[powerArrayRandomIndex] * 1000
: stationTemplate.power[powerArrayRandomIndex]
- } else {
+ } else if (typeof stationTemplate.power === 'number') {
stationInfo.maximumPower =
stationTemplate.powerUnit === PowerUnits.KILO_WATT
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- stationTemplate.power! * 1000
+ ? stationTemplate.power * 1000
: stationTemplate.power
}
stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo)
const getConfiguredMaxNumberOfConnectors = (stationTemplate: ChargingStationTemplate): number => {
let configuredMaxNumberOfConnectors = 0
- if (isNotEmptyArray(stationTemplate.numberOfConnectors)) {
+ if (isNotEmptyArray<number>(stationTemplate.numberOfConnectors)) {
const numberOfConnectors = stationTemplate.numberOfConnectors
configuredMaxNumberOfConnectors =
numberOfConnectors[Math.floor(secureRandom() * numberOfConnectors.length)]
- } else if (stationTemplate.numberOfConnectors != null) {
+ } else if (typeof stationTemplate.numberOfConnectors === 'number') {
configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors
} else if (stationTemplate.Connectors != null && stationTemplate.Evses == null) {
configuredMaxNumberOfConnectors =
start: chargingSchedule.startSchedule,
})
) {
- if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) {
+ if (isNotEmptyArray<ChargingSchedulePeriod>(chargingSchedule.chargingSchedulePeriod)) {
const chargingSchedulePeriodCompareFn = (
a: ChargingSchedulePeriod,
b: ChargingSchedulePeriod
) {
if (
!OCPPConstants.OCPP_MEASURANDS_SUPPORTED.includes(
- sampledValueTemplates[index]?.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
+ sampledValueTemplates[index].measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
)
) {
logger.warn(
)
} else if (
phase != null &&
- sampledValueTemplates[index]?.phase === phase &&
- sampledValueTemplates[index]?.measurand === measurand &&
+ sampledValueTemplates[index].phase === phase &&
+ sampledValueTemplates[index].measurand === measurand &&
getConfigurationKey(
chargingStation,
StandardParametersKey.MeterValuesSampledData
return sampledValueTemplates[index]
} else if (
phase == null &&
- sampledValueTemplates[index]?.phase == null &&
- sampledValueTemplates[index]?.measurand === measurand &&
+ sampledValueTemplates[index].phase == null &&
+ sampledValueTemplates[index].measurand === measurand &&
getConfigurationKey(
chargingStation,
StandardParametersKey.MeterValuesSampledData
return sampledValueTemplates[index]
} else if (
measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- (sampledValueTemplates[index]?.measurand == null ||
- sampledValueTemplates[index]?.measurand === measurand)
+ (sampledValueTemplates[index].measurand == null ||
+ sampledValueTemplates[index].measurand === measurand)
) {
return sampledValueTemplates[index]
}
} from 'date-fns'
import { getRandomValues, randomBytes, randomUUID } from 'node:crypto'
import { env, nextTick } from 'node:process'
-import { is } from 'rambda'
+import { is, isNotEmpty, type NonEmptyArray, type ReadonlyNonEmptyArray } from 'rambda'
import {
type JsonType,
return env.VCAP_APPLICATION != null
}
-export const isNotEmptyString = (value: unknown): value is string => {
+declare const nonEmptyString: unique symbol
+type NonEmptyString = { [nonEmptyString]: true } & string
+export const isNotEmptyString = (value: unknown): value is NonEmptyString => {
return typeof value === 'string' && value.trim().length > 0
}
-export const isNotEmptyArray = (value: unknown): value is unknown[] => {
- return Array.isArray(value) && value.length > 0
+export const isNotEmptyArray = <T>(
+ value: unknown
+): value is NonEmptyArray<T> | ReadonlyNonEmptyArray<T> => {
+ return Array.isArray(value) && isNotEmpty<T>(value as T[])
}
export const insertAt = (str: string, subStr: string, pos: number): string =>