X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationUtils.ts;h=370e030ccc5068eb457dc42dfbd3b999c4102864;hb=9383b2b1e4f256645b787d674bbd7a44b85dd3eb;hp=8978f0c8805fcf4c01c733bad855415f84a60710;hpb=fc040c43a050868c037485c658de49576f00fa55;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 8978f0c8..370e030c 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -5,9 +5,10 @@ import { fileURLToPath } from 'url'; 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'; @@ -17,11 +18,10 @@ import type { ChargingProfile, ChargingSchedulePeriod } from '../types/ocpp/Char 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'; @@ -30,6 +30,8 @@ import Utils from '../utils/Utils'; import type ChargingStation from './ChargingStation'; import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; +const moduleName = 'ChargingStationUtils'; + export class ChargingStationUtils { private constructor() { // This is intentional @@ -174,32 +176,6 @@ export class ChargingStationUtils { 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, @@ -238,7 +214,7 @@ export class ChargingStationUtils { delete stationTemplate.chargeBoxSerialNumberPrefix; delete stationTemplate.chargePointSerialNumberPrefix; delete stationTemplate.meterSerialNumberPrefix; - return stationTemplate; + return stationTemplate as unknown as ChargingStationInfo; } public static createStationInfoHash(stationInfo: ChargingStationInfo): void { @@ -330,6 +306,7 @@ export class ChargingStationUtils { limit: number; matchingChargingProfile: ChargingProfile; } | null { + const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`; for (const chargingProfile of chargingProfiles) { // Set helpers const currentMoment = moment(); @@ -373,10 +350,7 @@ export class ChargingStationUtils { limit: schedulePeriod.limit, matchingChargingProfile: chargingProfile, }; - logger.debug( - `${logPrefix} Matching charging profile found for power limitation: %j`, - result - ); + logger.debug(debugLogMsg, result); return result; } // Find the right schedule period @@ -390,10 +364,7 @@ export class ChargingStationUtils { limit: lastButOneSchedule.limit, matchingChargingProfile: chargingProfile, }; - logger.debug( - `${logPrefix} Matching charging profile found for power limitation: %j`, - result - ); + logger.debug(debugLogMsg, result); return result; } // Keep it @@ -409,10 +380,7 @@ export class ChargingStationUtils { limit: lastButOneSchedule.limit, matchingChargingProfile: chargingProfile, }; - logger.debug( - `${logPrefix} Matching charging profile found for power limitation: %j`, - result - ); + logger.debug(debugLogMsg, result); return result; } } @@ -449,7 +417,7 @@ export class ChargingStationUtils { 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}` ); @@ -477,10 +445,10 @@ export class ChargingStationUtils { 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}` @@ -492,7 +460,7 @@ export class ChargingStationUtils { ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData - )?.value.includes(measurand) + )?.value.includes(measurand) === true ) { return sampledValueTemplates[index]; } else if ( @@ -502,7 +470,7 @@ export class ChargingStationUtils { ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData - )?.value.includes(measurand) + )?.value.includes(measurand) === true ) { return sampledValueTemplates[index]; } else if ( @@ -539,9 +507,15 @@ export class ChargingStationUtils { 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}'`); @@ -554,12 +528,12 @@ export class ChargingStationUtils { ): 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;