mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[bsblan] Minor SAT fixes (#14138)
* Minor SAT fixes Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
32909fa237
commit
bbc885725f
@ -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";
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user