From 9383b2b1e4f256645b787d674bbd7a44b85dd3eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 25 Sep 2022 00:44:47 +0200 Subject: [PATCH] Fix strict boolean checks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 2 +- src/charging-station/ChargingStationUtils.ts | 24 ++++++++++++------- .../ChargingStationWorkerBroadcastChannel.ts | 2 +- .../ui-server/ui-services/UIServiceUtils.ts | 3 ++- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 0a3d544a..90bba2ef 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -632,7 +632,7 @@ export default class ChargingStation { parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); } - public hasFeatureProfile(featureProfile: SupportedFeatureProfiles) { + public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean { return ChargingStationConfigurationUtils.getConfigurationKey( this, StandardParametersKey.SupportedFeatureProfiles diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index e6b9c17d..370e030c 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -417,7 +417,7 @@ export class ChargingStationUtils { phase?: MeterValuePhase ): SampledValueTemplate | undefined { const onPhaseStr = phase ? `on phase ${phase} ` : ''; - if (!Constants.SUPPORTED_MEASURANDS.includes(measurand)) { + if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) { logger.warn( `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}` ); @@ -445,10 +445,10 @@ export class ChargingStationUtils { index++ ) { if ( - !Constants.SUPPORTED_MEASURANDS.includes( + Constants.SUPPORTED_MEASURANDS.includes( sampledValueTemplates[index]?.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - ) + ) === false ) { logger.warn( `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}` @@ -460,7 +460,7 @@ export class ChargingStationUtils { ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData - )?.value.includes(measurand) + )?.value.includes(measurand) === true ) { return sampledValueTemplates[index]; } else if ( @@ -470,7 +470,7 @@ export class ChargingStationUtils { ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, StandardParametersKey.MeterValuesSampledData - )?.value.includes(measurand) + )?.value.includes(measurand) === true ) { return sampledValueTemplates[index]; } else if ( @@ -507,9 +507,15 @@ export class ChargingStationUtils { chargingStation: ChargingStation ): boolean { const isRequestCommand = Object.values(RequestCommand).includes(command); - if (isRequestCommand && !chargingStation.stationInfo?.commandsSupport?.outgoingCommands) { + if ( + isRequestCommand === true && + !chargingStation.stationInfo?.commandsSupport?.outgoingCommands + ) { return true; - } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) { + } else if ( + isRequestCommand === true && + chargingStation.stationInfo?.commandsSupport?.outgoingCommands + ) { return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false; } logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`); @@ -522,12 +528,12 @@ export class ChargingStationUtils { ): boolean { const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command); if ( - isIncomingRequestCommand && + isIncomingRequestCommand === true && !chargingStation.stationInfo?.commandsSupport?.incomingCommands ) { return true; } else if ( - isIncomingRequestCommand && + isIncomingRequestCommand === true && chargingStation.stationInfo?.commandsSupport?.incomingCommands ) { return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false; diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 00780f2f..274267ca 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -268,7 +268,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca [ BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR, BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, - ].includes(command) === false && delete requestPayload.connectorIds; + ].includes(command) === true && delete requestPayload.connectorIds; } private commandResponseToResponsePayload( diff --git a/src/charging-station/ui-server/ui-services/UIServiceUtils.ts b/src/charging-station/ui-server/ui-services/UIServiceUtils.ts index c0199828..a3cb11b1 100644 --- a/src/charging-station/ui-server/ui-services/UIServiceUtils.ts +++ b/src/charging-station/ui-server/ui-services/UIServiceUtils.ts @@ -36,7 +36,8 @@ export class UIServiceUtils { protocol: Protocol, version: ProtocolVersion ): boolean => - Object.values(Protocol).includes(protocol) && Object.values(ProtocolVersion).includes(version); + Object.values(Protocol).includes(protocol) === true && + Object.values(ProtocolVersion).includes(version) === true; public static getProtocolAndVersion = (protocolStr: string): [Protocol, ProtocolVersion] => { const protocolIndex = protocolStr.indexOf(Protocol.UI); -- 2.34.1