X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=8e2064905d7691525cd6b20fc885557b761b5cbb;hb=b2b606263e2676354259164d532ff9aa91ccdf87;hp=078fa0a09551ca56e9e8d66bb94aad9cb2dab92c;hpb=fa5995d65e5084241af14d0ab7453fbb2fc9d8a6;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 078fa0a0..8e206490 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,13 @@ import { type StatusNotificationRequest, type StatusNotificationResponse, } from '../../types'; -import { Utils, handleFileException, logger } from '../../utils'; +import { + handleFileException, + isNotEmptyArray, + isNotEmptyString, + logPrefix, + logger, +} from '../../utils'; export class OCPPServiceUtils { protected constructor() { @@ -185,17 +191,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,9 +275,9 @@ 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) { handleFileException( filePath, @@ -305,7 +320,7 @@ export class OCPPServiceUtils { chargingStation.getConnectorStatus(connectorId)?.MeterValues; for ( let index = 0; - Utils.isNotEmptyArray(sampledValueTemplates) === true && index < sampledValueTemplates.length; + isNotEmptyArray(sampledValueTemplates) === true && index < sampledValueTemplates.length; index++ ) { if ( @@ -383,9 +398,9 @@ export class OCPPServiceUtils { methodName?: string ): string => { const logMsg = - Utils.isNotEmptyString(moduleName) && Utils.isNotEmptyString(methodName) + isNotEmptyString(moduleName) && isNotEmptyString(methodName) ? ` OCPP ${ocppVersion} | ${moduleName}.${methodName}:` : ` OCPP ${ocppVersion} |`; - return Utils.logPrefix(logMsg); + return logPrefix(logMsg); }; }