) => Promise<void>,
this,
connectorId
- ).catch(() => {
- /* This is intentional */
- });
+ ).catch(Constants.EMPTY_FUNCTION);
} else if (this.connectorsStatus.get(connectorId)?.start === true) {
logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
}
}
public openWSConnection(
- options: WsOptions = this.stationInfo?.wsOptions ?? {},
+ options: WsOptions = this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT,
params: { closeOpened?: boolean; terminateOpened?: boolean } = {
closeOpened: false,
terminateOpened: false,
},
reset: true,
},
- stationTemplate?.firmwareUpgrade ?? {}
+ stationTemplate?.firmwareUpgrade ?? Constants.EMPTY_OBJECT
);
stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime)
? stationTemplate.resetTime * 1000
fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
}
const configurationData: ChargingStationConfiguration =
- Utils.cloneObject(this.getConfigurationFromFile()) ?? {};
+ Utils.cloneObject(this.getConfigurationFromFile()) ?? Constants.EMPTY_OBJECT;
this.ocppConfiguration?.configurationKey &&
(configurationData.configurationKey = this.ocppConfiguration.configurationKey);
this.stationInfo && (configurationData.stationInfo = this.stationInfo);
`${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}`
);
this.openWSConnection(
- { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout },
+ {
+ ...(this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT),
+ handshakeTimeout: reconnectTimeout,
+ },
{ closeOpened: true }
);
this.wsConnectionRestarted = true;
import type { ChargingStation } from './internal';
import type { ConfigurationKey, ConfigurationKeyType } from '../types';
-import { logger } from '../utils';
+import { Constants, logger } from '../utils';
type ConfigurationKeyOptions = { readonly?: boolean; visible?: boolean; reboot?: boolean };
type DeleteConfigurationKeyParams = { save?: boolean; caseInsensitive?: boolean };
},
params: AddConfigurationKeyParams = { overwrite: false, save: false }
): void {
- options = options ?? ({} as ConfigurationKeyOptions);
+ options = options ?? (Constants.EMPTY_OBJECT as ConfigurationKeyOptions);
options.readonly = options?.readonly ?? false;
options.visible = options?.visible ?? true;
options.reboot = options?.reboot ?? false;
randomSerialNumber: true,
}
): void {
- params = params ?? {};
+ params = params ?? Constants.EMPTY_OBJECT;
params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true;
params.randomSerialNumber = params?.randomSerialNumber ?? true;
const serialNumberSuffix = params?.randomSerialNumber
) => Promise<void>,
chargingStation,
`${commandPayload.type}Reset` as OCPP16StopTransactionReason
- ).catch(() => {
- /* This is intentional */
- });
+ ).catch(Constants.EMPTY_FUNCTION);
logger.info(
`${chargingStation.logPrefix()} ${
commandPayload.type
) => Promise<void>,
this,
chargingStation
- ).catch(() => {
- /* This is intentional */
- });
+ ).catch(Constants.EMPTY_FUNCTION);
} else {
setTimeout(() => {
- this.updateFirmware(chargingStation).catch(() => {
- /* Intentional */
- });
+ this.updateFirmware(chargingStation).catch(Constants.EMPTY_FUNCTION);
}, retrieveDate?.getTime() - now);
}
return OCPPConstants.OCPP_RESPONSE_EMPTY;
.then((response) => {
chargingStation.bootNotificationResponse = response;
})
- .catch(() => {
- /* This is intentional */
- });
+ .catch(Constants.EMPTY_FUNCTION);
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
case OCPP16MessageTrigger.Heartbeat:
triggerMessage: true,
}
)
- .catch(() => {
- /* This is intentional */
- });
+ .catch(Constants.EMPTY_FUNCTION);
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
case OCPP16MessageTrigger.StatusNotification:
triggerMessage: true,
}
)
- .catch(() => {
- /* This is intentional */
- });
+ .catch(Constants.EMPTY_FUNCTION);
} else {
for (const connectorId of chargingStation.connectors.keys()) {
chargingStation.ocppRequestService
triggerMessage: true,
}
)
- .catch(() => {
- /* This is intentional */
- });
+ .catch(Constants.EMPTY_FUNCTION);
}
}
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
chargingStation,
OCPP16StandardParametersKey.HeartbeatInterval,
payload.interval.toString(),
- {},
+ Constants.EMPTY_OBJECT,
{ overwrite: true, save: true }
);
ChargingStationConfigurationUtils.addConfigurationKey(
connectorId,
OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT
);
- let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
+ let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates =
+ Constants.EMPTY_OBJECT;
if (chargingStation.getNumberOfPhases() === 3) {
powerPerPhaseSampledValueTemplates = {
L1: OCPP16ServiceUtils.getSampledValueTemplate(
powerSampledValueTemplate.measurand ??
OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
} measurand value`;
- const powerMeasurandValues = {} as MeasurandValues;
+ const powerMeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues;
const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1;
const connectorMaximumAvailablePower =
chargingStation.getConnectorMaximumAvailablePower(connectorId);
connectorId,
OCPP16MeterValueMeasurand.CURRENT_IMPORT
);
- let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
+ let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates =
+ Constants.EMPTY_OBJECT;
if (chargingStation.getNumberOfPhases() === 3) {
currentPerPhaseSampledValueTemplates = {
L1: OCPP16ServiceUtils.getSampledValueTemplate(
currentSampledValueTemplate.measurand ??
OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
} measurand value`;
- const currentMeasurandValues: MeasurandValues = {} as MeasurandValues;
+ const currentMeasurandValues: MeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues;
const connectorMaximumAvailablePower =
chargingStation.getConnectorMaximumAvailablePower(connectorId);
let connectorMaximumAmperage: number;
RegistrationStatusEnumType,
type ResponseHandler,
} from '../../../types';
-import { logger } from '../../../utils';
+import { Constants, logger } from '../../../utils';
import { OCPP20ServiceUtils, OCPPResponseService } from '../internal';
const moduleName = 'OCPP20ResponseService';
chargingStation,
OCPP20OptionalVariableName.HeartbeatInterval,
payload.interval.toString(),
- {},
+ Constants.EMPTY_OBJECT,
{ overwrite: true, save: true }
);
chargingStation.heartbeatSetInterval
TriggerMessageStatus,
UnlockStatus,
} from '../../types';
+import { Constants } from '../../utils';
export class OCPPConstants {
- static readonly OCPP_REQUEST_EMPTY = Object.freeze({});
- static readonly OCPP_RESPONSE_EMPTY = Object.freeze({});
+ static readonly OCPP_REQUEST_EMPTY = Constants.EMPTY_FREEZED_OBJECT;
+ static readonly OCPP_RESPONSE_EMPTY = Constants.EMPTY_FREEZED_OBJECT;
static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: GenericStatus.Accepted });
static readonly OCPP_RESPONSE_REJECTED = Object.freeze({ status: GenericStatus.Rejected });
ErrorType.GENERIC_ERROR,
`WebSocket closed or errored for buffered message id '${messageId}' with content '${messageToSend}'`,
commandName,
- (messagePayload as JsonObject)?.details ?? {}
+ (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT
)
);
} else if (wsClosedOrErrored) {
ErrorType.GENERIC_ERROR,
`WebSocket closed or errored for non buffered message id '${messageId}' with content '${messageToSend}'`,
commandName,
- (messagePayload as JsonObject)?.details ?? {}
+ (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT
);
// Reject response
if (messageType !== MessageType.CALL_MESSAGE) {
ErrorType.GENERIC_ERROR,
`Timeout for message id '${messageId}'`,
commandName,
- (messagePayload as JsonObject)?.details ?? {}
+ (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT
),
() => {
messageType === MessageType.CALL_MESSAGE && chargingStation.requests.delete(messageId);
ResponseStatus,
type UIServerConfiguration,
} from '../../types';
-import { Utils, logger } from '../../utils';
+import { Constants, Utils, logger } from '../../utils';
import { AbstractUIServer, UIServerUtils } from '../internal';
const moduleName = 'UIHttpServer';
const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload;
this.uiServices
.get(version)
- ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {}))
- .catch(() => {
- /* Error caught by AbstractUIService */
- });
+ ?.requestHandler(
+ this.buildProtocolRequest(
+ uuid,
+ procedureName,
+ body ?? Constants.EMPTY_FREEZED_OBJECT
+ )
+ )
+ .catch(Constants.EMPTY_FUNCTION);
});
} else {
throw new BaseError(`Unsupported HTTP method: '${req.method}'`);
type UIServerConfiguration,
WebSocketCloseEventStatusCode,
} from '../../types';
-import { Utils, logger } from '../../utils';
+import { Constants, Utils, logger } from '../../utils';
import { AbstractUIServer, UIServerUtils } from '../internal';
const moduleName = 'UIWebSocketServer';
}
const [requestId] = request as ProtocolRequest;
this.responseHandlers.set(requestId, ws);
- this.uiServices
- .get(version)
- ?.requestHandler(request)
- .catch(() => {
- /* Error caught by AbstractUIService */
- });
+ this.uiServices.get(version)?.requestHandler(request).catch(Constants.EMPTY_FUNCTION);
});
ws.on('error', (error) => {
logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error);
type JsonType,
type RequestCommand,
} from '../types';
+import { Constants } from '../utils';
export class OCPPError extends BaseError {
code: ErrorType;
this.code = code ?? ErrorType.GENERIC_ERROR;
this.command = command;
- this.details = details ?? {};
+ this.details = details ?? Constants.EMPTY_FREEZED_OBJECT;
}
}
const entryName = entry.name;
// Initialize command statistics
if (!this.statistics.statisticsData.has(entryName)) {
- this.statistics.statisticsData.set(entryName, {});
+ this.statistics.statisticsData.set(entryName, Constants.EMPTY_OBJECT);
}
// Update current statistics
this.statistics.updatedAt = new Date();
import lockfile from 'proper-lockfile';
import { FileType, type Statistics } from '../../types';
-import { FileUtils, Utils } from '../../utils';
+import { Constants, FileUtils, Utils } from '../../utils';
import { Storage } from '../internal';
export class JsonFileStorage extends Storage {
}
await release();
})
- .catch(() => {
- /* This is intentional */
- });
+ .catch(Constants.EMPTY_FUNCTION);
}
public open(): void {
static readonly MAX_RANDOM_INTEGER = 281474976710654;
+ static EMPTY_OBJECT = {};
+ static readonly EMPTY_FREEZED_OBJECT = Object.freeze({});
+ static readonly EMPTY_FUNCTION = Object.freeze(() => {
+ /* This is intentional */
+ });
+
private constructor() {
// This is intentional
}
poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE,
poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER,
- poolOptions: {},
- messageHandler: () => {
- /* This is intentional */
- },
+ poolOptions: WorkerConstants.EMPTY_OBJECT,
+ messageHandler: WorkerConstants.EMPTY_FUNCTION,
}
) {
if (!workerScript) {
export class WorkerConstants {
+ public static EMPTY_OBJECT = {};
+ public static readonly EMPTY_FUNCTION = Object.freeze(() => {
+ /* This is intentional */
+ });
+
static readonly DEFAULT_ELEMENT_START_DELAY = 0;
static readonly DEFAULT_WORKER_START_DELAY = 500;
static readonly POOL_MAX_INACTIVE_TIME = 60000;
if (!isMainThread) {
throw new Error('Cannot get a worker implementation outside the main thread');
}
- workerOptions = workerOptions ?? ({} as WorkerOptions);
+ workerOptions = workerOptions ?? (WorkerConstants.EMPTY_OBJECT as WorkerOptions);
workerOptions.workerStartDelay =
workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY;
workerOptions.elementStartDelay =
workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY;
- workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions<Worker>);
+ workerOptions.poolOptions =
+ workerOptions?.poolOptions ?? (WorkerConstants.EMPTY_OBJECT as PoolOptions<Worker>);
workerOptions?.messageHandler &&
(workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
let workerImplementation: WorkerAbstract<T> | null = null;
import { Worker } from 'node:worker_threads';
import { WorkerAbstract } from './WorkerAbstract';
+import { WorkerConstants } from './WorkerConstants';
import {
type MessageHandler,
type WorkerData,
const worker = new Worker(this.workerScript);
worker.on(
'message',
- (
- this.workerOptions?.messageHandler ??
- (() => {
- /* This is intentional */
- })
- ).bind(this) as MessageHandler<Worker>
+ (this.workerOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION).bind(
+ this
+ ) as MessageHandler<Worker>
);
worker.on('error', WorkerUtils.defaultErrorHandler.bind(this) as (err: Error) => void);
worker.on('exit', (code) => {