From: Jérôme Benoit Date: Mon, 3 Oct 2022 10:34:03 +0000 (+0200) Subject: More strict boolean checks X-Git-Tag: v1.1.75~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=inline;h=ed6cfcff3ef6596cdf76c68f600effcb25dece72;p=e-mobility-charging-stations-simulator.git More strict boolean checks Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index db1b699c..7b98ed35 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -216,7 +216,10 @@ export default class ChargingStation { } public isRegistered(): boolean { - return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState()); + return ( + this.isInUnknownState() === false && + (this.isInAcceptedState() === true || this.isInPendingState() === true) + ); } public isChargingStationAvailable(): boolean { @@ -1326,7 +1329,7 @@ export default class ChargingStation { logger.info( `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded` ); - if (!this.isRegistered()) { + if (this.isRegistered() === false) { // Send BootNotification let registrationRetryCount = 0; do { @@ -1336,7 +1339,7 @@ export default class ChargingStation { >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, { skipBufferingOnError: true, }); - if (!this.isRegistered()) { + if (this.isRegistered() === false) { this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++; await Utils.sleep( this.bootNotificationResponse?.interval @@ -1345,12 +1348,12 @@ export default class ChargingStation { ); } } while ( - !this.isRegistered() && + this.isRegistered() === false && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1) ); } - if (this.isRegistered()) { + if (this.isRegistered() === true) { if (this.isInAcceptedState()) { await this.startMessageSequence(); } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 52751b4b..ae37c7b2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -298,12 +298,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ); } if ( - chargingStation.isRegistered() || - (!chargingStation.getOcppStrictCompliance() && chargingStation.isInUnknownState()) + chargingStation.isRegistered() === true || + (chargingStation.getOcppStrictCompliance() === false && + chargingStation.isInUnknownState() === true) ) { if ( - this.incomingRequestHandlers.has(commandName) && - OCPP16ServiceUtils.isIncomingRequestCommandSupported(chargingStation, commandName) + this.incomingRequestHandlers.has(commandName) === true && + OCPP16ServiceUtils.isIncomingRequestCommandSupported(chargingStation, commandName) === true ) { try { this.validatePayload(chargingStation, commandName, commandPayload); diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 3bb9f6ce..afc4773d 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -149,7 +149,7 @@ export default class OCPP16RequestService extends OCPPRequestService { commandParams?: JsonType, params?: RequestParams ): Promise { - if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName)) { + if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) { const requestPayload = this.buildRequestPayload( chargingStation, commandName, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 1dc583db..4ba89706 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -174,10 +174,13 @@ export default class OCPP16ResponseService extends OCPPResponseService { payload: JsonType, requestPayload: JsonType ): Promise { - if (chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) { + if ( + chargingStation.isRegistered() === true || + commandName === OCPP16RequestCommand.BOOT_NOTIFICATION + ) { if ( - this.responseHandlers.has(commandName) && - OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) + this.responseHandlers.has(commandName) === true && + OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true ) { try { this.validatePayload(chargingStation, commandName, payload);