From: Jérôme Benoit Date: Sun, 2 Oct 2022 20:50:02 +0000 (+0200) Subject: Strict boolean checks X-Git-Tag: v1.1.75~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1789ba2c82f32832d577617a615d79c889eea1e6;p=e-mobility-charging-stations-simulator.git Strict boolean checks Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index fb6e9d28..232ad2cd 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -152,7 +152,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.stopConnector(connectorId); break; } - if (!this.chargingStation.isInAcceptedState()) { + if (this.chargingStation.isInAcceptedState() === false) { logger.error( this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is not in accepted state' @@ -160,7 +160,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.stopConnector(connectorId); break; } - if (!this.chargingStation.isChargingStationAvailable()) { + if (this.chargingStation.isChargingStationAvailable() === false) { logger.info( this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is unavailable' @@ -168,7 +168,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.stopConnector(connectorId); break; } - if (!this.chargingStation.isConnectorAvailable(connectorId)) { + if (this.chargingStation.isConnectorAvailable(connectorId) === false) { logger.info( `${this.logPrefix( connectorId diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 40b84621..db1b699c 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1764,8 +1764,7 @@ export default class ChargingStation { } else if ( !this.getConnectorStatus(connectorId)?.status && (this.isChargingStationAvailable() === false || - (this.isChargingStationAvailable() === true && - this.isConnectorAvailable(connectorId) === false)) + this.isConnectorAvailable(connectorId) === false) ) { chargePointStatus = ChargePointStatus.UNAVAILABLE; } else if ( diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7b13004e..ceaea14e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -537,15 +537,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload: SetChargingProfileRequest ): SetChargingProfileResponse { if ( - !OCPP16ServiceUtils.checkFeatureProfile( + OCPP16ServiceUtils.checkFeatureProfile( chargingStation, OCPP16SupportedFeatureProfiles.SmartCharging, OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE - ) + ) === false ) { return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED; } - if (!chargingStation.getConnectorStatus(commandPayload.connectorId)) { + if (chargingStation.connectors.has(commandPayload.connectorId) === false) { logger.error( `${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${ commandPayload.connectorId @@ -596,8 +596,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ) { return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN; } - const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId); - if (!connectorStatus) { + if (chargingStation.connectors.has(commandPayload.connectorId) === false) { logger.error( `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${ commandPayload.connectorId @@ -605,6 +604,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ); return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN; } + const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId); if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) { connectorStatus.chargingProfiles = []; logger.debug( @@ -729,8 +729,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload: RemoteStartTransactionRequest ): Promise { const transactionConnectorId = commandPayload.connectorId; - const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId); - if (transactionConnectorId) { + if (chargingStation.connectors.has(transactionConnectorId) === true) { const remoteStartTransactionLogMsg = chargingStation.logPrefix() + ' Transaction remotely STARTED on ' + @@ -748,24 +747,25 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer status: OCPP16ChargePointStatus.PREPARING, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); + const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId); connectorStatus.status = OCPP16ChargePointStatus.PREPARING; - if (chargingStation.isChargingStationAvailable() && connectorStatus) { + if (chargingStation.isChargingStationAvailable() === true) { // Check if authorized - if (chargingStation.getAuthorizeRemoteTxRequests()) { + if (chargingStation.getAuthorizeRemoteTxRequests() === true) { let authorized = false; if ( - chargingStation.getLocalAuthListEnabled() && - chargingStation.hasAuthorizedTags() && + chargingStation.getLocalAuthListEnabled() === true && + chargingStation.hasAuthorizedTags() === true && chargingStation.authorizedTagsCache .getAuthorizedTags( ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo) ) - .find((value) => value === commandPayload.idTag) + .find((idTag) => idTag === commandPayload.idTag) ) { connectorStatus.localAuthorizeIdTag = commandPayload.idTag; connectorStatus.idTagLocalAuthorized = true; authorized = true; - } else if (chargingStation.getMustAuthorizeAtRemoteStart()) { + } else if (chargingStation.getMustAuthorizeAtRemoteStart() === true) { connectorStatus.authorizeIdTag = commandPayload.idTag; const authorizeResponse: OCPP16AuthorizeResponse = await chargingStation.ocppRequestService.requestHandler< @@ -782,14 +782,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled` ); } - if (authorized) { + if (authorized === true) { // Authorization successful, start transaction if ( this.setRemoteStartTransactionChargingProfile( chargingStation, transactionConnectorId, commandPayload.chargingProfile - ) + ) === true ) { connectorStatus.transactionRemoteStarted = true; if ( @@ -830,7 +830,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer chargingStation, transactionConnectorId, commandPayload.chargingProfile - ) + ) === true ) { connectorStatus.transactionRemoteStarted = true; if ( @@ -971,11 +971,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload: GetDiagnosticsRequest ): Promise { if ( - !OCPP16ServiceUtils.checkFeatureProfile( + OCPP16ServiceUtils.checkFeatureProfile( chargingStation, OCPP16SupportedFeatureProfiles.FirmwareManagement, OCPP16IncomingRequestCommand.GET_DIAGNOSTICS - ) + ) === false ) { return Constants.OCPP_RESPONSE_EMPTY; } diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index f72f2c3c..1dc583db 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -557,8 +557,8 @@ export default class OCPP16ResponseService extends OCPPResponseService { ], })); if ( - !chargingStation.isChargingStationAvailable() || - !chargingStation.isConnectorAvailable(transactionConnectorId) + chargingStation.isChargingStationAvailable() === false || + chargingStation.isConnectorAvailable(transactionConnectorId) === false ) { await chargingStation.ocppRequestService.requestHandler< OCPP16StatusNotificationRequest,