diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/api/BsbLanApiCaller.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/api/BsbLanApiCaller.java index c6ea44352b6..a2842fbb827 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/api/BsbLanApiCaller.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/api/BsbLanApiCaller.java @@ -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"; } } diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/configuration/BsbLanBridgeConfiguration.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/configuration/BsbLanBridgeConfiguration.java index 96c5ba1717d..7a64648ed30 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/configuration/BsbLanBridgeConfiguration.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/configuration/BsbLanBridgeConfiguration.java @@ -12,40 +12,44 @@ */ 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; } diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBridgeHandler.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBridgeHandler.java index ae5150197dd..070216fa3fe 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBridgeHandler.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBridgeHandler.java @@ -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); } } } diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java index c804a5a57bf..3afd4369e0a 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java @@ -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;