import moment from 'moment';
import BaseError from '../exception/BaseError';
-import type ChargingStationInfo from '../types/ChargingStationInfo';
-import ChargingStationTemplate, {
+import type { ChargingStationInfo } from '../types/ChargingStationInfo';
+import {
AmpereUnits,
+ type ChargingStationTemplate,
CurrentType,
Voltage,
} from '../types/ChargingStationTemplate';
import { StandardParametersKey } from '../types/ocpp/Configuration';
import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
import {
- BootNotificationRequest,
+ type BootNotificationRequest,
IncomingRequestCommand,
RequestCommand,
} from '../types/ocpp/Requests';
-import { WebSocketCloseEventStatusString } from '../types/WebSocket';
import { WorkerProcessType } from '../types/Worker';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
}
}
- public static getConfiguredNumberOfConnectors(
- index: number,
- stationTemplate: ChargingStationTemplate
- ): number {
+ public static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
let configuredMaxConnectors: number;
- if (!Utils.isEmptyArray(stationTemplate.numberOfConnectors)) {
+ if (Utils.isEmptyArray(stationTemplate.numberOfConnectors) === false) {
const numberOfConnectors = stationTemplate.numberOfConnectors as number[];
- // Distribute evenly the number of connectors
- configuredMaxConnectors = numberOfConnectors[(index - 1) % numberOfConnectors.length];
- } else if (!Utils.isUndefined(stationTemplate.numberOfConnectors)) {
+ configuredMaxConnectors =
+ numberOfConnectors[Math.floor(Utils.secureRandom() * numberOfConnectors.length)];
+ } else if (Utils.isUndefined(stationTemplate.numberOfConnectors) === false) {
configuredMaxConnectors = stationTemplate.numberOfConnectors as number;
} else {
configuredMaxConnectors = stationTemplate?.Connectors[0]
return Configuration.getWorker().processType === WorkerProcessType.DYNAMIC_POOL;
}
- /**
- * Convert websocket error code to human readable string message
- *
- * @param code websocket error code
- * @returns human readable string message
- */
- public static getWebSocketCloseEventStatusString(code: number): string {
- if (code >= 0 && code <= 999) {
- return '(Unused)';
- } else if (code >= 1016) {
- if (code <= 1999) {
- return '(For WebSocket standard)';
- } else if (code <= 2999) {
- return '(For WebSocket extensions)';
- } else if (code <= 3999) {
- return '(For libraries and frameworks)';
- } else if (code <= 4999) {
- return '(For applications)';
- }
- }
- if (!Utils.isUndefined(WebSocketCloseEventStatusString[code])) {
- return WebSocketCloseEventStatusString[code] as string;
- }
- return '(Unknown)';
- }
-
public static warnDeprecatedTemplateKey(
template: ChargingStationTemplate,
key: string,
phase?: MeterValuePhase
): SampledValueTemplate | undefined {
const onPhaseStr = phase ? `on phase ${phase} ` : '';
- if (!Constants.SUPPORTED_MEASURANDS.includes(measurand)) {
+ if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) {
logger.warn(
`${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
);
index++
) {
if (
- !Constants.SUPPORTED_MEASURANDS.includes(
+ Constants.SUPPORTED_MEASURANDS.includes(
sampledValueTemplates[index]?.measurand ??
MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
- )
+ ) === false
) {
logger.warn(
`${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
ChargingStationConfigurationUtils.getConfigurationKey(
chargingStation,
StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
+ )?.value.includes(measurand) === true
) {
return sampledValueTemplates[index];
} else if (
ChargingStationConfigurationUtils.getConfigurationKey(
chargingStation,
StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
+ )?.value.includes(measurand) === true
) {
return sampledValueTemplates[index];
} else if (
chargingStation: ChargingStation
): boolean {
const isRequestCommand = Object.values(RequestCommand).includes(command);
- if (isRequestCommand && !chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
+ if (
+ isRequestCommand === true &&
+ !chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+ ) {
return true;
- } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
+ } else if (
+ isRequestCommand === true &&
+ chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+ ) {
return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
}
logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
): boolean {
const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
if (
- isIncomingRequestCommand &&
+ isIncomingRequestCommand === true &&
!chargingStation.stationInfo?.commandsSupport?.incomingCommands
) {
return true;
} else if (
- isIncomingRequestCommand &&
+ isIncomingRequestCommand === true &&
chargingStation.stationInfo?.commandsSupport?.incomingCommands
) {
return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;