More strict boolean checks
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Oct 2022 10:34:03 +0000 (12:34 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Oct 2022 10:34:03 +0000 (12:34 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts

index db1b699c3c55df94c9cc43c2ddb5e4f1eeca6c5a..7b98ed35858bd4c524cccb1af9222c0100e3922b 100644 (file)
@@ -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();
         }
index 52751b4bac994ddfc9e2bc0f68746093b7c2bb55..ae37c7b2e02707e49df9f18181300ecf4447dd38 100644 (file)
@@ -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);
index 3bb9f6ce4426965e97a20c690cbf67a996b0ca6b..afc4773d3cbc34914991faad8df89f6cdffbd4a9 100644 (file)
@@ -149,7 +149,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
     commandParams?: JsonType,
     params?: RequestParams
   ): Promise<ResponseType> {
-    if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName)) {
+    if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) {
       const requestPayload = this.buildRequestPayload<RequestType>(
         chargingStation,
         commandName,
index 1dc583dbb87736ace93e3caba5186ea26c2a5022..4ba89706feb8a4a38a52edcad386f880122090e9 100644 (file)
@@ -174,10 +174,13 @@ export default class OCPP16ResponseService extends OCPPResponseService {
     payload: JsonType,
     requestPayload: JsonType
   ): Promise<void> {
-    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);