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;
}
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://");
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";
}
}
*/
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;
}
// 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);
}
// 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);
}
}
}
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;