-import fs from 'node:fs';
-import path from 'node:path';
+import { readFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv';
type StatusNotificationRequest,
type StatusNotificationResponse,
} from '../../types';
-import { Constants, ErrorUtils, Utils, logger } from '../../utils';
+import { Utils, handleFileException, logger } from '../../utils';
export class OCPPServiceUtils {
protected constructor() {
chargingStation: ChargingStation,
connectorId: number,
status: ConnectorStatusEnum,
- evseId?: number
+ evseId?: number,
+ options: { send: boolean } = { send: true }
) {
- OCPPServiceUtils.checkConnectorStatusTransition(chargingStation, connectorId, status);
- await chargingStation.ocppRequestService.requestHandler<
- StatusNotificationRequest,
- StatusNotificationResponse
- >(
- chargingStation,
- RequestCommand.STATUS_NOTIFICATION,
- OCPPServiceUtils.buildStatusNotificationRequest(chargingStation, connectorId, status, evseId)
- );
+ options = { send: true, ...options };
+ if (options.send) {
+ OCPPServiceUtils.checkConnectorStatusTransition(chargingStation, connectorId, status);
+ await chargingStation.ocppRequestService.requestHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(
+ chargingStation,
+ RequestCommand.STATUS_NOTIFICATION,
+ OCPPServiceUtils.buildStatusNotificationRequest(
+ chargingStation,
+ connectorId,
+ status,
+ evseId
+ )
+ );
+ }
chargingStation.getConnectorStatus(connectorId).status = status;
}
moduleName?: string,
methodName?: string
): JSONSchemaType<T> {
- const filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), relativePath);
+ const filePath = join(dirname(fileURLToPath(import.meta.url)), relativePath);
try {
- return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
+ return JSON.parse(readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
} catch (error) {
- ErrorUtils.handleFileException(
+ handleFileException(
filePath,
FileType.JsonSchema,
error as NodeJS.ErrnoException,
unitMultiplier: 1,
}
): number {
- options.limitationEnabled = options?.limitationEnabled ?? true;
- options.unitMultiplier = options?.unitMultiplier ?? 1;
+ options = {
+ ...{
+ limitationEnabled: true,
+ unitMultiplier: 1,
+ },
+ ...options,
+ };
const parsedInt = parseInt(value);
const numberValue = isNaN(parsedInt) ? Infinity : parsedInt;
return options?.limitationEnabled