X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16RequestService.ts;h=ac1c1ac30d8810ac85e00de9b94b438e4e9876a0;hb=d8093be156ab575dbd44546ef4646a6338a27358;hp=b82599b768e08ed13cfff1586ef20d1b12190637;hpb=d193a94981cfed2c3d502eeca581ce4e9f0eebe5;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index b82599b7..ac1c1ac3 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -24,11 +24,7 @@ import { OCPPVersion, type RequestParams, } from '../../../types'; -import type { - OCPP16CancelReservationRequest, - OCPP16ReserveNowRequest, -} from '../../../types/ocpp/1.6/Requests'; -import { Constants, Utils } from '../../../utils'; +import { Constants, generateUUID } from '../../../utils'; import { OCPPRequestService } from '../OCPPRequestService'; import type { OCPPResponseService } from '../OCPPResponseService'; @@ -48,7 +44,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/Authorize.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -56,7 +52,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/BootNotification.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -64,7 +60,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -72,7 +68,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/Heartbeat.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -80,7 +76,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/MeterValues.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -88,7 +84,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/StatusNotification.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -96,7 +92,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/StartTransaction.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -104,7 +100,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/StopTransaction.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -112,7 +108,7 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/DataTransfer.json', moduleName, - 'constructor' + 'constructor', ), ], [ @@ -120,30 +116,14 @@ export class OCPP16RequestService extends OCPPRequestService { OCPP16ServiceUtils.parseJsonSchemaFile( 'assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json', moduleName, - 'constructor' - ), - ], - [ - OCPP16RequestCommand.RESERVE_NOW, - OCPP16ServiceUtils.parseJsonSchemaFile( - 'assets/json-schemas/ocpp/1.6/ReserveNow.json', - moduleName, - 'constructor' - ), - ], - [ - OCPP16RequestCommand.CANCEL_RESERVATION, - OCPP16ServiceUtils.parseJsonSchemaFile( - 'assets/json-schemas/ocpp/1.6/CancelReservation.json', - moduleName, - 'constructor' + 'constructor', ), ], ]); this.buildRequestPayload = this.buildRequestPayload.bind(this) as ( chargingStation: ChargingStation, commandName: OCPP16RequestCommand, - commandParams?: JsonType + commandParams?: JsonType, ) => Request; } @@ -151,16 +131,16 @@ export class OCPP16RequestService extends OCPPRequestService { chargingStation: ChargingStation, commandName: OCPP16RequestCommand, commandParams?: JsonType, - params?: RequestParams + params?: RequestParams, ): Promise { // FIXME?: add sanity checks on charging station availability, connector availability, connector status, etc. if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) { return (await this.sendMessage( chargingStation, - Utils.generateUUID(), + generateUUID(), this.buildRequestPayload(chargingStation, commandName, commandParams), commandName, - params + params, )) as ResponseType; } // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError(). @@ -168,16 +148,16 @@ export class OCPP16RequestService extends OCPPRequestService { ErrorType.NOT_SUPPORTED, `Unsupported OCPP command '${commandName}'`, commandName, - commandParams + commandParams, ); } private buildRequestPayload( chargingStation: ChargingStation, commandName: OCPP16RequestCommand, - commandParams?: JsonType + commandParams?: JsonType, ): Request { - let connectorId: number; + let connectorId: number | undefined; let energyActiveImportRegister: number; commandParams = commandParams as JsonObject; switch (commandName) { @@ -200,7 +180,7 @@ export class OCPP16RequestService extends OCPPRequestService { idTag: Constants.DEFAULT_IDTAG, meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId( commandParams?.connectorId as number, - true + true, ), timestamp: new Date(), ...commandParams, @@ -208,11 +188,11 @@ export class OCPP16RequestService extends OCPPRequestService { case OCPP16RequestCommand.STOP_TRANSACTION: chargingStation.getTransactionDataMeterValues() && (connectorId = chargingStation.getConnectorIdByTransactionId( - commandParams?.transactionId as number - )); + commandParams?.transactionId as number, + )!); energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId( commandParams?.transactionId as number, - true + true, ); return { idTag: chargingStation.getTransactionIdTag(commandParams?.transactionId as number), @@ -220,12 +200,12 @@ export class OCPP16RequestService extends OCPPRequestService { timestamp: new Date(), ...(chargingStation.getTransactionDataMeterValues() && { transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues( - chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue, + chargingStation.getConnectorStatus(connectorId!)!.transactionBeginMeterValue!, OCPP16ServiceUtils.buildTransactionEndMeterValue( chargingStation, - connectorId, - energyActiveImportRegister - ) + connectorId!, + energyActiveImportRegister, + ), ), }), ...commandParams, @@ -237,7 +217,7 @@ export class OCPP16RequestService extends OCPPRequestService { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `Unsupported OCPP command '${commandName}'`, commandName, - commandParams + commandParams, ); } }