]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bsblan] Minor SAT fixes (#14138)
authorlsiepel <leosiepel@gmail.com>
Thu, 12 Jan 2023 20:07:31 +0000 (21:07 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Jan 2023 20:07:31 +0000 (21:07 +0100)
* Minor SAT fixes

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/api/BsbLanApiCaller.java
bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/configuration/BsbLanBridgeConfiguration.java
bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBridgeHandler.java
bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java

index c6ea44352b6bdef312b9467d71e434e6646048e3..a2842fbb827baa7fa4db708d06381012eabb3b2e 100644 (file)
@@ -17,7 +17,7 @@ import static org.openhab.binding.bsblan.internal.BsbLanBindingConstants.API_TIM
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -92,10 +92,10 @@ public class BsbLanApiCaller {
     }
 
     private String createApiBaseUrl() {
-        final String host = bridgeConfig.host == null ? "" : bridgeConfig.host.trim();
-        final String username = bridgeConfig.username == null ? "" : bridgeConfig.username.trim();
-        final String password = bridgeConfig.password == null ? "" : bridgeConfig.password.trim();
-        final String passkey = bridgeConfig.passkey == null ? "" : bridgeConfig.passkey.trim();
+        final String host = bridgeConfig.host.trim();
+        final String username = bridgeConfig.username.trim();
+        final String password = bridgeConfig.password.trim();
+        final String passkey = bridgeConfig.passkey.trim();
 
         StringBuilder url = new StringBuilder();
         url.append("http://");
@@ -131,7 +131,7 @@ public class BsbLanApiCaller {
                 String content = BsbLanApiContentConverter.toJson(request);
                 logger.trace("api request content: '{}'", content);
                 if (!content.isBlank()) {
-                    contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8")));
+                    contentStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
                     contentType = "application/json";
                 }
             }
index 96c5ba1717d0b7af4458d8b15c3941b34c33c127..7a64648ed3085402473d619d2da78abf89f18dce 100644 (file)
  */
 package org.openhab.binding.bsblan.internal.configuration;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.bsblan.internal.BsbLanBindingConstants;
+
 /**
  * The {@link BsbLanBridgeConfiguration} is the class used to match the
  * bridge configuration.
  *
  * @author Peter Schraffl - Initial contribution
  */
+@NonNullByDefault
 public class BsbLanBridgeConfiguration {
     /**
      * Hostname or IP address of the device
      */
-    public String host;
+    public String host = "";
 
     /**
      * HTTP port where device is listening
      */
-    public Integer port;
+    public Integer port = BsbLanBindingConstants.DEFAULT_API_PORT;
 
     /**
      * For "security" feature of BSB-LAN devices
      */
-    public String passkey;
+    public String passkey = "";
 
     /**
      * HTTP Basic Authentication User
      */
-    public String username;
+    public String username = "";
 
     /**
      * HTTP Basic Authentication Password
      */
-    public String password;
+    public String password = "";
 
     /**
      * Value refresh interval
      */
-    public Integer refreshInterval;
+    public Integer refreshInterval = BsbLanBindingConstants.DEFAULT_REFRESH_INTERVAL;
 }
index ae5150197ddd2b9db99e50f15c697c31151fcbb2..070216fa3fe4f7f45ec727bafa56e9945da9f634 100644 (file)
@@ -78,23 +78,19 @@ public class BsbLanBridgeHandler extends BaseBridgeHandler {
 
         // validate 'host' configuration
         String host = bridgeConfig.host;
-        if (host == null || host.isBlank()) {
+        if (host.isBlank()) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "Parameter 'host' is mandatory and must be configured");
             return;
         }
 
         // validate 'refreshInterval' configuration
-        if (bridgeConfig.refreshInterval != null && bridgeConfig.refreshInterval < MIN_REFRESH_INTERVAL) {
+        if (bridgeConfig.refreshInterval < MIN_REFRESH_INTERVAL) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     String.format("Parameter 'refreshInterval' must be at least %d seconds", MIN_REFRESH_INTERVAL));
             return;
         }
 
-        if (bridgeConfig.port == null) {
-            bridgeConfig.port = DEFAULT_API_PORT;
-        }
-
         // all checks succeeded, start refreshing
         startAutomaticRefresh(bridgeConfig);
     }
@@ -160,9 +156,7 @@ public class BsbLanBridgeHandler extends BaseBridgeHandler {
         // use a local variable to avoid the build warning "Potential null pointer access"
         ScheduledFuture<?> localRefreshJob = refreshJob;
         if (localRefreshJob == null || localRefreshJob.isCancelled()) {
-            int interval = (config.refreshInterval != null) ? config.refreshInterval.intValue()
-                    : DEFAULT_REFRESH_INTERVAL;
-            refreshJob = scheduler.scheduleWithFixedDelay(this::doRefresh, 0, interval, TimeUnit.SECONDS);
+            refreshJob = scheduler.scheduleWithFixedDelay(this::doRefresh, 0, config.refreshInterval, TimeUnit.SECONDS);
         }
     }
 }
index c804a5a57bf1c70289e2c5f686f598e5e0c6ddf2..3afd4369e0ab21fec9df3fa1cab4d185911ee247 100644 (file)
@@ -18,7 +18,6 @@ import org.apache.commons.lang3.StringEscapeUtils;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterDTO;
-import org.openhab.binding.bsblan.internal.handler.BsbLanParameterHandler;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.QuantityType;