mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[hdanywhere] Fix build warnings and SAT errors (#20553)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
+10
-5
@@ -19,6 +19,8 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.hdanywhere.internal.handler.Mhub4K431Handler;
|
||||
import org.openhab.binding.hdanywhere.internal.handler.MultiroomPlusHandler;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@@ -36,6 +38,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
*
|
||||
* @author Karel Goderis - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.hdanywhere")
|
||||
public class HDanywhereHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
@@ -48,7 +51,7 @@ public class HDanywhereHandlerFactory extends BaseThingHandlerFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThingHandler createHandler(Thing thing) {
|
||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
if (thingTypeUID.equals(THING_TYPE_MULTIROOMPLUS)) {
|
||||
@@ -63,8 +66,8 @@ public class HDanywhereHandlerFactory extends BaseThingHandlerFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
|
||||
ThingUID bridgeUID) {
|
||||
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
|
||||
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
|
||||
if (HDanywhereBindingConstants.THING_TYPE_MULTIROOMPLUS.equals(thingTypeUID)) {
|
||||
ThingUID matrixUID = getMultiroomPlusUID(thingTypeUID, thingUID, configuration);
|
||||
return super.createThing(thingTypeUID, configuration, matrixUID, null);
|
||||
@@ -77,7 +80,8 @@ public class HDanywhereHandlerFactory extends BaseThingHandlerFactory {
|
||||
"The thing type " + thingTypeUID + " is not supported by the HDanywhere binding.");
|
||||
}
|
||||
|
||||
private ThingUID getMultiroomPlusUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) {
|
||||
private ThingUID getMultiroomPlusUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
|
||||
Configuration configuration) {
|
||||
String ipAddress = (String) configuration.get(MultiroomPlusHandler.IP_ADDRESS);
|
||||
|
||||
if (thingUID == null) {
|
||||
@@ -86,7 +90,8 @@ public class HDanywhereHandlerFactory extends BaseThingHandlerFactory {
|
||||
return thingUID;
|
||||
}
|
||||
|
||||
private ThingUID getMhub4K431UID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) {
|
||||
private ThingUID getMhub4K431UID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
|
||||
Configuration configuration) {
|
||||
String ipAddress = (String) configuration.get(Mhub4K431Handler.IP_ADDRESS);
|
||||
|
||||
if (thingUID == null) {
|
||||
|
||||
+31
-17
@@ -22,6 +22,8 @@ import java.util.Properties;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.hdanywhere.internal.HDanywhereBindingConstants.Port;
|
||||
import org.openhab.core.io.net.http.HttpUtil;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
@@ -43,6 +45,7 @@ import com.google.gson.reflect.TypeToken;
|
||||
*
|
||||
* @author Karel Goderis - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Mhub4K431Handler extends BaseThingHandler {
|
||||
|
||||
// List of Configurations constants
|
||||
@@ -52,11 +55,11 @@ public class Mhub4K431Handler extends BaseThingHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(Mhub4K431Handler.class);
|
||||
|
||||
private ScheduledFuture<?> pollingJob;
|
||||
private @Nullable ScheduledFuture<?> pollingJob;
|
||||
protected final Gson gson = new Gson();
|
||||
|
||||
private final int timeout = 5000;
|
||||
private final int numberOfPorts = 4;
|
||||
private static final int TIMEOUT = 5000;
|
||||
private static final int NUMBER_OF_PORTS = 4;
|
||||
|
||||
public Mhub4K431Handler(Thing thing) {
|
||||
super(thing);
|
||||
@@ -66,19 +69,19 @@ public class Mhub4K431Handler extends BaseThingHandler {
|
||||
public void initialize() {
|
||||
logger.debug("Initializing HDanywhere MHUB 4K (4×3+1) matrix handler.");
|
||||
|
||||
if (pollingJob == null || pollingJob.isCancelled()) {
|
||||
int pollingInterval = ((BigDecimal) getConfig().get(POLLING_INTERVAL)).intValue();
|
||||
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, pollingInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
int pollingInterval = ((BigDecimal) getConfig().get(POLLING_INTERVAL)).intValue();
|
||||
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, pollingInterval, TimeUnit.SECONDS);
|
||||
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
logger.debug("Disposing HDanywhere matrix handler.");
|
||||
ScheduledFuture<?> pollingJob = this.pollingJob;
|
||||
if (pollingJob != null && !pollingJob.isCancelled()) {
|
||||
pollingJob.cancel(true);
|
||||
pollingJob = null;
|
||||
this.pollingJob = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,20 +94,31 @@ public class Mhub4K431Handler extends BaseThingHandler {
|
||||
String content = "{tag:ptn}";
|
||||
InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
String response = HttpUtil.executeUrl(httpMethod, url, null, stream, null, timeout);
|
||||
response = response.trim();
|
||||
response = response.substring(1, response.length() - 1);
|
||||
String response = HttpUtil.executeUrl(httpMethod, url, null, stream, null, TIMEOUT);
|
||||
|
||||
if (response != null) {
|
||||
response = response.trim();
|
||||
response = response.substring(1, response.length() - 1);
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
|
||||
java.lang.reflect.Type type = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
|
||||
Map<String, String> map = gson.fromJson(response, type);
|
||||
if (map == null) {
|
||||
logger.trace("Received null map from HDanywhere matrix. Response was '{}'", response);
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
String inputChannel = map.get("Inputchannel");
|
||||
if (inputChannel == null) {
|
||||
logger.trace("Received null input channel from HDanywhere matrix. Response was '{}'", response);
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfPorts; i++) {
|
||||
for (int i = 0; i < NUMBER_OF_PORTS; i++) {
|
||||
DecimalType decimalType = new DecimalType(String.valueOf(inputChannel.charAt(i)));
|
||||
updateState(new ChannelUID(getThing().getUID(), Port.get(i + 1).channelID()), decimalType);
|
||||
}
|
||||
@@ -129,14 +143,14 @@ public class Mhub4K431Handler extends BaseThingHandler {
|
||||
int sourcePort = Integer.valueOf(command.toString());
|
||||
int outputPort = Port.get(channelID).toNumber();
|
||||
|
||||
if (sourcePort > numberOfPorts) {
|
||||
if (sourcePort > NUMBER_OF_PORTS) {
|
||||
// nice try - we can switch to a port that does not physically exist
|
||||
logger.warn("Source port {} goes beyond the physical number of {} ports available on the matrix {}",
|
||||
new Object[] { sourcePort, numberOfPorts, host });
|
||||
} else if (outputPort > numberOfPorts) {
|
||||
new Object[] { sourcePort, NUMBER_OF_PORTS, host });
|
||||
} else if (outputPort > NUMBER_OF_PORTS) {
|
||||
// nice try - we can switch to a port that does not physically exist
|
||||
logger.warn("Output port {} goes beyond the physical number of {} ports available on the matrix {}",
|
||||
new Object[] { outputPort, numberOfPorts, host });
|
||||
new Object[] { outputPort, NUMBER_OF_PORTS, host });
|
||||
} else {
|
||||
String httpMethod = "POST";
|
||||
String url = "http://" + host + "/cgi-bin/MMX32_Keyvalue.cgi";
|
||||
@@ -152,7 +166,7 @@ public class Mhub4K431Handler extends BaseThingHandler {
|
||||
|
||||
try {
|
||||
HttpUtil.executeUrl(httpMethod, url, httpHeaders, stream,
|
||||
"application/x-www-form-urlencoded; charset=UTF-8", timeout);
|
||||
"application/x-www-form-urlencoded; charset=UTF-8", TIMEOUT);
|
||||
} catch (IOException e) {
|
||||
logger.debug("Communication with device failed", e);
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
|
||||
+9
-3
@@ -19,6 +19,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.hdanywhere.internal.HDanywhereBindingConstants.Port;
|
||||
import org.openhab.core.io.net.http.HttpUtil;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
@@ -38,6 +40,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Karel Goderis - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class MultiroomPlusHandler extends BaseThingHandler {
|
||||
|
||||
// List of Configurations constants
|
||||
@@ -47,7 +50,7 @@ public class MultiroomPlusHandler extends BaseThingHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MultiroomPlusHandler.class);
|
||||
|
||||
private ScheduledFuture<?> pollingJob;
|
||||
private @Nullable ScheduledFuture<?> pollingJob;
|
||||
|
||||
/**
|
||||
* the timeout to use for connecting to a given host (defaults to 5000
|
||||
@@ -132,9 +135,11 @@ public class MultiroomPlusHandler extends BaseThingHandler {
|
||||
@Override
|
||||
public void dispose() {
|
||||
logger.debug("Disposing HDanywhere matrix handler.");
|
||||
|
||||
ScheduledFuture<?> pollingJob = this.pollingJob;
|
||||
if (pollingJob != null && !pollingJob.isCancelled()) {
|
||||
pollingJob.cancel(true);
|
||||
pollingJob = null;
|
||||
this.pollingJob = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +152,10 @@ public class MultiroomPlusHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private synchronized void onUpdate() {
|
||||
ScheduledFuture<?> pollingJob = this.pollingJob;
|
||||
if (pollingJob == null || pollingJob.isCancelled()) {
|
||||
int pollingInterval = ((BigDecimal) getConfig().get(POLLING_INTERVAL)).intValue();
|
||||
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, pollingInterval, TimeUnit.SECONDS);
|
||||
this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, pollingInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user