X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=7433f71d27c4278d39f77caa85315fb89b5daefb;hb=d972af76b6d7d1d2a099d254eacf45245b5316ac;hp=c5387f33f9c693f41ff21f1b20d9f40d7c5cd514;hpb=c3da35d496cbb2c78e85fb3d2e125ffd6fd297f4;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index c5387f33..7433f71d 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1,5 +1,5 @@ -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'; @@ -30,7 +30,7 @@ import { type StatusNotificationRequest, type StatusNotificationResponse, } from '../../types'; -import { Constants, ErrorUtils, Utils, logger } from '../../utils'; +import { Utils, handleFileException, logger } from '../../utils'; export class OCPPServiceUtils { protected constructor() { @@ -185,17 +185,26 @@ export class OCPPServiceUtils { 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; } @@ -260,11 +269,11 @@ export class OCPPServiceUtils { moduleName?: string, methodName?: string ): JSONSchemaType { - 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; + return JSON.parse(readFileSync(filePath, 'utf8')) as JSONSchemaType; } catch (error) { - ErrorUtils.handleFileException( + handleFileException( filePath, FileType.JsonSchema, error as NodeJS.ErrnoException, @@ -363,8 +372,13 @@ export class OCPPServiceUtils { 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