import java.util.Set;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
/**
*
* @author Karel Goderis - Initial contribution
*/
+@NonNullByDefault
public class KNXBindingConstants {
public static final String BINDING_ID = "knx";
import org.openhab.core.types.Type;
import tuwien.auto.calimero.datapoint.Datapoint;
-import tuwien.auto.calimero.process.ProcessEvent;
/**
* This interface must be implemented by classes that provide a type mapping
* When a command or status update is sent to an item on the openHAB event bus,
* it must be clear, in which format it must be sent to KNX and vice versa.
*
- * @author Kai Kreuzer
+ * @author Kai Kreuzer - Initial contribution
*
*/
@NonNullByDefault
* maps a datapoint value to an openHAB command or state
*
* @param datapoint the source datapoint
- * @param data the datapoint value as an ASDU byte array (see <code>{@link ProcessEvent}.getASDU()</code>)
+ * @param data the datapoint value as an ASDU byte array (see
+ * <code>{@link tuwien.auto.calimero.process.ProcessEvent}.getASDU()</code>)
* @return a command or state of openHAB
*/
@Nullable
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.knx.internal.client.InboundSpec;
-import org.openhab.binding.knx.internal.client.OutboundSpec;
import tuwien.auto.calimero.GroupAddress;
import tuwien.auto.calimero.KNXFormatException;
/**
* Return the data point type.
* <p>
- * See {@link InboundSpec#getDPT()} and {@link OutboundSpec#getDPT()}.
+ * See {@link org.openhab.binding.knx.internal.client.InboundSpec#getDPT()} and
+ * {@link org.openhab.binding.knx.internal.client.OutboundSpec#getDPT()}.
*
* @return the data point type.
*/
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.client.InboundSpec;
* @author Simon Kaufmann - initial contribution and API.
*
*/
+@NonNullByDefault
public class ListenSpecImpl extends AbstractSpec implements InboundSpec {
private final List<GroupAddress> listenAddresses;
});
}
- private <T> T nullify(T target, @Nullable Consumer<T> lastWill) {
+ private <T> @Nullable T nullify(T target, @Nullable Consumer<T> lastWill) {
if (target != null && lastWill != null) {
lastWill.accept(target);
}
@Override
public boolean isConnected() {
- return link != null && link.isOpen();
+ final var tmpLink = link;
+ return tmpLink != null && tmpLink.isOpen();
}
@Override
*/
package org.openhab.binding.knx.internal.client;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
import tuwien.auto.calimero.KNXException;
import tuwien.auto.calimero.knxnetip.KNXnetIPConnection;
import tuwien.auto.calimero.link.KNXNetworkLinkIP;
* @author Simon Kaufmann - initial contribution and API
*
*/
+@NonNullByDefault
public class CustomKNXNetworkLinkIP extends KNXNetworkLinkIP {
public static final int TUNNELING = KNXNetworkLinkIP.TUNNELING;
OPERATION_TIMEOUT);
if ((elements == null ? 0 : toUnsigned(elements)) == 1) {
Thread.sleep(OPERATION_INTERVAL);
- String ManufacturerID = Manufacturer.getName(toUnsigned(getClient().readDeviceProperties(address,
+ String manufacturerID = Manufacturer.getName(toUnsigned(getClient().readDeviceProperties(address,
DEVICE_OBJECT, PID.MANUFACTURER_ID, 1, 1, false, OPERATION_TIMEOUT)));
Thread.sleep(OPERATION_INTERVAL);
String serialNo = toHex(getClient().readDeviceProperties(address, DEVICE_OBJECT, PID.SERIAL_NUMBER, 1,
String firmwareRevision = Integer.toString(toUnsigned(getClient().readDeviceProperties(address,
DEVICE_OBJECT, PID.FIRMWARE_REVISION, 1, 1, false, OPERATION_TIMEOUT)));
- ret.put(MANUFACTURER_NAME, ManufacturerID);
+ ret.put(MANUFACTURER_NAME, manufacturerID);
if (serialNo != null) {
ret.put(MANUFACTURER_SERIAL_NO, serialNo);
}
}
ret.put(MANUFACTURER_FIRMWARE_REVISION, firmwareRevision);
logger.debug("Identified device {} as a {}, type {}, revision {}, serial number {}", address,
- ManufacturerID, hardwareType, firmwareRevision, serialNo);
+ manufacturerID, hardwareType, firmwareRevision, serialNo);
} else {
logger.debug("The KNX device with address {} does not expose a Device Object", address);
}
import java.util.Enumeration;
import java.util.concurrent.ScheduledExecutorService;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author Simon Kaufmann - initial contribution and API.
*
*/
+@NonNullByDefault
public class SerialClient extends AbstractKNXClient {
private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
}
@Override
- protected @NonNull KNXNetworkLink establishConnection() throws KNXException, InterruptedException {
+ protected KNXNetworkLink establishConnection() throws KNXException, InterruptedException {
try {
RXTXVersion.getVersion();
logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}.", serialPort);
"The serial FT1.2 KNX connection requires the RXTX libraries to be available, but they could not be found!",
e);
} catch (KNXException e) {
- if (e.getMessage().startsWith("can not open serial port")) {
+ final String msg = e.getMessage();
+ if ((msg != null) && (msg.startsWith("can not open serial port"))) {
StringBuilder sb = new StringBuilder("Available ports are:\n");
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
- if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
+ if ((id != null) && (id.getPortType() == CommPortIdentifier.PORT_SERIAL)) {
sb.append(id.getName());
sb.append("\n");
}
import java.math.BigDecimal;
-import org.openhab.binding.knx.internal.handler.KNXBridgeBaseThingHandler;
+import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * {@link KNXBridgeBaseThingHandler} configuration
+ * {@link org.openhab.binding.knx.internal.handler.KNXBridgeBaseThingHandler} configuration
*
* @author Simon Kaufmann - initial contribution and API
*
*/
+@NonNullByDefault
public class BridgeConfiguration {
- private int autoReconnectPeriod;
- private BigDecimal readingPause;
- private BigDecimal readRetriesLimit;
- private BigDecimal responseTimeout;
+ private int autoReconnectPeriod = 0;
+ private BigDecimal readingPause = BigDecimal.valueOf(0);
+ private BigDecimal readRetriesLimit = BigDecimal.valueOf(0);
+ private BigDecimal responseTimeout = BigDecimal.valueOf(0);
public int getAutoReconnectPeriod() {
return autoReconnectPeriod;
import java.math.BigDecimal;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* Configuration object for the device thing handler.
*
* @author Karel Goderis - Initial contribution
* @author Simon Kaufmann - refactoring & cleanup
*/
+@NonNullByDefault
public class DeviceConfig {
- private String address;
- private boolean fetch;
- private BigDecimal pingInterval;
- private BigDecimal readInterval;
+ private String address = "";
+ private boolean fetch = false;
+ private BigDecimal pingInterval = BigDecimal.valueOf(0);
+ private BigDecimal readInterval = BigDecimal.valueOf(0);
public String getAddress() {
return address;
import java.math.BigDecimal;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* IP Bridge handler configuration object.
*
* @author Simon Kaufmann - initial contribution and API
*
*/
+@NonNullByDefault
public class IPBridgeConfiguration extends BridgeConfiguration {
- private boolean useNAT;
- private String type;
- private String ipAddress;
- private BigDecimal portNumber;
- private String localIp;
- private String localSourceAddr;
+ private boolean useNAT = false;
+ private String type = "";
+ private String ipAddress = "";
+ private BigDecimal portNumber = BigDecimal.valueOf(0);
+ private String localIp = "";
+ private String localSourceAddr = "";
public Boolean getUseNAT() {
return useNAT;
*/
package org.openhab.binding.knx.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* Serial Bridge configuration object.
*
* @author Simon Kaufmann - initial contribution and API.
*
*/
+@NonNullByDefault
public class SerialBridgeConfiguration extends BridgeConfiguration {
- private String serialPort;
+ private String serialPort = "";
public String getSerialPort() {
return serialPort;
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
ThingUID bridgeUID) {
if (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) {
- ThingUID IPBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration);
- return super.createThing(thingTypeUID, configuration, IPBridgeUID, null);
+ ThingUID ipBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration);
+ return super.createThing(thingTypeUID, configuration, ipBridgeUID, null);
}
if (THING_TYPE_SERIAL_BRIDGE.equals(thingTypeUID)) {
ThingUID serialBridgeUID = getSerialBridgeThingUID(thingTypeUID, thingUID, configuration);
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.client.DeviceInspector;
}
@Override
- public void bridgeStatusChanged(@NonNull ThingStatusInfo bridgeStatusInfo) {
+ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
attachToClient();
} else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
}
DeviceConfig config = getConfigAs(DeviceConfig.class);
try {
- if (config.getAddress() != null && !config.getAddress().isEmpty()) {
+ if (!config.getAddress().isEmpty()) {
updateStatus(ThingStatus.UNKNOWN);
address = new IndividualAddress(config.getAddress());
}
protected void detachFromClient() {
- if (pollingJob != null) {
- pollingJob.cancel(true);
+ final var pollingJobSynced = pollingJob;
+ if (pollingJobSynced != null) {
+ pollingJobSynced.cancel(true);
pollingJob = null;
}
- if (descriptionJob != null) {
- descriptionJob.cancel(true);
+ final var descriptionJobSynced = descriptionJob;
+ if (descriptionJobSynced != null) {
+ descriptionJobSynced.cancel(true);
descriptionJob = null;
}
cancelReadFutures();
*/
package org.openhab.binding.knx.internal.handler;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* @author Karel Goderis - Initial contribution
*/
+@NonNullByDefault
public class DeviceConstants {
private DeviceConstants() {
private void cancelChannelFutures() {
for (ScheduledFuture<?> future : channelFutures.values()) {
- if (future != null && !future.isDone()) {
+ if (!future.isDone()) {
future.cancel(true);
}
}
@Override
protected void cancelReadFutures() {
for (ScheduledFuture<?> future : readFutures.values()) {
- if (future != null && !future.isDone()) {
+ if (!future.isDone()) {
future.cancel(true);
}
}
boolean useNAT = false;
int ipConnectionType;
if (MODE_TUNNEL.equalsIgnoreCase(connectionTypeString)) {
- useNAT = config.getUseNAT() != null ? config.getUseNAT() : false;
+ useNAT = config.getUseNAT();
ipConnectionType = CustomKNXNetworkLinkIP.TUNNELING;
} else if (MODE_ROUTER.equalsIgnoreCase(connectionTypeString)) {
useNAT = false;
- if (ip == null || ip.isEmpty()) {
+ if (ip.isEmpty()) {
ip = KNXBindingConstants.DEFAULT_MULTICAST_IP;
}
ipConnectionType = CustomKNXNetworkLinkIP.ROUTING;
connectionTypeString));
return;
}
- if (ip == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "The 'ipAddress' of the gateway must be configured in 'TUNNEL' mode");
- return;
- }
- if (config.getLocalIp() != null && !config.getLocalIp().isEmpty()) {
+ if (!config.getLocalIp().isEmpty()) {
localEndPoint = new InetSocketAddress(config.getLocalIp(), 0);
} else {
localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0);
thing.getUID(), config.getResponseTimeout().intValue(), config.getReadingPause().intValue(),
config.getReadRetriesLimit().intValue(), getScheduler(), this);
- client.initialize();
+ final var tmpClient = client;
+ if (tmpClient != null) {
+ tmpClient.initialize();
+ }
}
@Override
public void dispose() {
super.dispose();
- if (client != null) {
- client.dispose();
+ final var tmpClient = client;
+ if (tmpClient != null) {
+ tmpClient.dispose();
client = null;
}
}
import java.util.Collections;
import java.util.Set;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
* @author Simon Kaufmann - initial contribution and API.
*
*/
+@NonNullByDefault
public class KNXChannelTypeTest {
- private KNXChannelType ct;
+ private KNXChannelType ct = new MyKNXChannelType("");
@BeforeEach
public void setup() {
ct = new MyKNXChannelType("");
}
+ @SuppressWarnings("null")
@Test
- public void testParse_withDPT_multiple_withRead() {
+ public void testParseWithDptMultipleWithRead() {
ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
assertEquals("5.001", res.getDPT());
assertEquals(2, res.getReadGAs().size());
}
+ @SuppressWarnings("null")
@Test
- public void testParse_withDPT_multiple_withoutRead() {
+ public void testParseWithDptMultipleWithoutRead() {
ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
assertEquals("5.001", res.getDPT());
assertEquals(0, res.getReadGAs().size());
}
+ @SuppressWarnings("null")
@Test
- public void testParse_withoutDPT_single_withoutRead() {
+ public void testParseWithoutDptSingleWithoutRead() {
ChannelConfiguration res = ct.parse("1/3/22");
assertNull(res.getDPT());
assertEquals(0, res.getReadGAs().size());
}
+ @SuppressWarnings("null")
@Test
- public void testParse_withoutDPT_single_witRead() {
+ public void testParseWithoutDptSingleWitRead() {
ChannelConfiguration res = ct.parse("<1/3/22");
assertNull(res.getDPT());
assertEquals(1, res.getReadGAs().size());
}
+ @SuppressWarnings("null")
@Test
- public void testParse_twoLevel() {
+ public void testParseTwoLevel() {
ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
assertEquals("3/1024", res.getMainGA().getGA());
assertEquals(2, res.getListenGAs().size());
assertEquals(2, res.getReadGAs().size());
}
+ @SuppressWarnings("null")
@Test
- public void testParse_freeLevel() {
+ public void testParseFreeLevel() {
ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
assertEquals("4610", res.getMainGA().getGA());
assertEquals(2, res.getListenGAs().size());
}
@Override
- protected @NonNull Set<@NonNull String> getAllGAKeys() {
+ protected Set<String> getAllGAKeys() {
return Collections.emptySet();
}
@Override
- protected @NonNull String getDefaultDPT(@NonNull String gaConfigKey) {
+ protected String getDefaultDPT(String gaConfigKey) {
return "";
}
}
import static org.junit.jupiter.api.Assertions.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DecimalType;
* @author Simon Kaufmann - initial contribution and API
*
*/
+@NonNullByDefault
public class KNXCoreTypeMapperTest {
@Test
- public void testToDPTValue_trailingZeroesStrippedOff() {
+ public void testToDPTValueTrailingZeroesStrippedOff() {
assertEquals("3", new KNXCoreTypeMapper().toDPTValue(new DecimalType("3"), "17.001"));
assertEquals("3", new KNXCoreTypeMapper().toDPTValue(new DecimalType("3.0"), "17.001"));
}