X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20ResponseService.ts;h=442c6c1d6d488086d999be08e2616fb906cf1b98;hb=44eb6026079c8dc2c77b10a96a42d0c0b2da7c8f;hp=add126e408933e9576c90ea59988057bbe73d2be;hpb=6e939d9e416de33fa1c64fc7f4eb6be70954f69c;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index add126e4..442c6c1d 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from 'url'; import type { JSONSchemaType } from 'ajv'; +import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; import OCPPError from '../../../exception/OCPPError'; import type { JsonObject, JsonType } from '../../../types/JsonType'; import { @@ -24,7 +25,6 @@ import { RegistrationStatusEnumType, ResponseHandler } from '../../../types/ocpp import logger from '../../../utils/Logger'; import type ChargingStation from '../../ChargingStation'; import OCPPResponseService from '../OCPPResponseService'; -import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; const moduleName = 'OCPP20ResponseService'; @@ -50,53 +50,29 @@ export default class OCPP20ResponseService extends OCPPResponseService { this.jsonSchemas = new Map>([ [ OCPP20RequestCommand.BOOT_NOTIFICATION, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json' + ), ], [ OCPP20RequestCommand.HEARTBEAT, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json' + ), ], [ OCPP20RequestCommand.STATUS_NOTIFICATION, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json' + ), ], ]); this.jsonIncomingRequestResponseSchemas = new Map([ [ OCPP20IncomingRequestCommand.CLEAR_CACHE, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json' + ), ], ]); this.validatePayload.bind(this); @@ -204,10 +180,18 @@ export default class OCPP20ResponseService extends OCPPResponseService { : logger.info(logMsg); } else { logger.error( - chargingStation.logPrefix() + - ' Charging station boot notification response received: %j with undefined registration status', + `${chargingStation.logPrefix()} Charging station boot notification response received: %j with undefined registration status`, payload ); } } + + private parseJsonSchemaFile(relativePath: string): JSONSchemaType { + return JSON.parse( + fs.readFileSync( + path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath), + 'utf8' + ) + ) as JSONSchemaType; + } }