Strict boolean checks
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 20:50:02 +0000 (22:50 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 20:50:02 +0000 (22:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts

index fb6e9d28c1f92ee7766104dd4559a79eeb94725e..232ad2cd4533ce68ac79e05b676599cf4eeafd42 100644 (file)
@@ -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
index 40b846217556023b671d8f31a0f5d7996cc2bd0c..db1b699c3c55df94c9cc43c2ddb5e4f1eeca6c5a 100644 (file)
@@ -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 (
index 7b13004ee90185b85c5aa89ae36f213ff57852dd..ceaea14e607aebb0d0c9be9c8354a0ccb429188f 100644 (file)
@@ -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<DefaultResponse> {
     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<GetDiagnosticsResponse> {
     if (
-      !OCPP16ServiceUtils.checkFeatureProfile(
+      OCPP16ServiceUtils.checkFeatureProfile(
         chargingStation,
         OCPP16SupportedFeatureProfiles.FirmwareManagement,
         OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
-      )
+      ) === false
     ) {
       return Constants.OCPP_RESPONSE_EMPTY;
     }
index f72f2c3ccc73b48cd3092920d6e027796a4f5284..1dc583dbb87736ace93e3caba5186ea26c2a5022 100644 (file)
@@ -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,