From: Jérôme Benoit Date: Sun, 30 Jul 2023 19:39:32 +0000 (+0200) Subject: fix: fix some undefined/null checks X-Git-Tag: v1.2.20~74 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=611d5cd2c94317acc7959c930bf962847b059e86;p=e-mobility-charging-stations-simulator.git fix: fix some undefined/null checks Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 20c8e81a..1dc0a809 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -408,7 +408,7 @@ export class AutomaticTransactionGenerator extends AsyncResource { ++this.connectorsStatus.get(connectorId)!.authorizeRequests!; if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { if ( - isNullOrUndefined(this.chargingStation.getConnectorStatus(connectorId)!.authorizeIdTag) + isNullOrUndefined(this.chargingStation.getConnectorStatus(connectorId)?.authorizeIdTag) ) { logger.warn( `${this.chargingStation.logPrefix()} IdTag ${idTag} is not set as authorized remotely, applying deferred initialization`, diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 46598b0b..f5b568dc 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -826,10 +826,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ): Promise { const { connectorId: transactionConnectorId, idTag, chargingProfile } = commandPayload; if ( - (chargingStation.getConnectorStatus(transactionConnectorId)!.status === + (chargingStation.getConnectorStatus(transactionConnectorId)?.status === OCPP16ChargePointStatus.Reserved && chargingStation.getReservationBy('connectorId', transactionConnectorId)?.idTag !== idTag) || - (chargingStation.getConnectorStatus(0)!.status === OCPP16ChargePointStatus.Reserved && + (chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved && chargingStation.getReservationBy('connectorId', 0)?.idTag !== idTag) ) { return OCPP16Constants.OCPP_RESPONSE_REJECTED; @@ -896,7 +896,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { idTag, reservationId: chargingStation.getReservationBy( 'connectorId', - chargingStation.getConnectorStatus(0)!.status === OCPP16ChargePointStatus.Reserved + chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved ? 0 : transactionConnectorId, )!, @@ -937,7 +937,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { idTag, reservationId: chargingStation.getReservationBy( 'connectorId', - chargingStation.getConnectorStatus(0)!.status === OCPP16ChargePointStatus.Reserved + chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved ? 0 : transactionConnectorId, )!, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index e5caf4bf..2d4853f0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -640,18 +640,17 @@ export class OCPP16ResponseService extends OCPPResponseService { requestPayload.meterStart, ); const reservedOnConnectorZero = - chargingStation.getConnectorStatus(0)!.status === OCPP16ChargePointStatus.Reserved; + chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved; if ( - chargingStation.getConnectorStatus(transactionConnectorId)!.status === + chargingStation.getConnectorStatus(transactionConnectorId)?.status === OCPP16ChargePointStatus.Reserved || reservedOnConnectorZero ) { - const reservation = chargingStation.getReservationBy( - 'connectorId', - reservedOnConnectorZero ? 0 : transactionConnectorId, - )!; await chargingStation.removeReservation( - reservation, + chargingStation.getReservationBy( + 'connectorId', + reservedOnConnectorZero ? 0 : transactionConnectorId, + )!, ReservationTerminationReason.TRANSACTION_STARTED, ); }