[knx] Reduce compiler warnings (#12518)

added NonNullByDefault annotations
rename functions and local variables not matching the naming scheme

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2022-03-27 11:27:39 +02:00 committed by GitHub
parent 9b7478c1fb
commit 414d7a84e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 96 additions and 65 deletions

View File

@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
/** /**
@ -26,6 +27,7 @@ import org.openhab.core.thing.ThingTypeUID;
* *
* @author Karel Goderis - Initial contribution * @author Karel Goderis - Initial contribution
*/ */
@NonNullByDefault
public class KNXBindingConstants { public class KNXBindingConstants {
public static final String BINDING_ID = "knx"; public static final String BINDING_ID = "knx";

View File

@ -17,7 +17,6 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.types.Type; import org.openhab.core.types.Type;
import tuwien.auto.calimero.datapoint.Datapoint; import tuwien.auto.calimero.datapoint.Datapoint;
import tuwien.auto.calimero.process.ProcessEvent;
/** /**
* This interface must be implemented by classes that provide a type mapping * This interface must be implemented by classes that provide a type mapping
@ -25,7 +24,7 @@ import tuwien.auto.calimero.process.ProcessEvent;
* When a command or status update is sent to an item on the openHAB event bus, * 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. * 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 @NonNullByDefault
@ -45,7 +44,8 @@ public interface KNXTypeMapper {
* maps a datapoint value to an openHAB command or state * maps a datapoint value to an openHAB command or state
* *
* @param datapoint the source datapoint * @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 * @return a command or state of openHAB
*/ */
@Nullable @Nullable

View File

@ -14,8 +14,6 @@ package org.openhab.binding.knx.internal.channel;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; 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.GroupAddress;
import tuwien.auto.calimero.KNXFormatException; import tuwien.auto.calimero.KNXFormatException;
@ -57,7 +55,8 @@ public abstract class AbstractSpec {
/** /**
* Return the data point type. * Return the data point type.
* <p> * <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. * @return the data point type.
*/ */

View File

@ -17,6 +17,7 @@ import static java.util.stream.Collectors.toList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.client.InboundSpec; import org.openhab.binding.knx.internal.client.InboundSpec;
@ -28,6 +29,7 @@ import tuwien.auto.calimero.GroupAddress;
* @author Simon Kaufmann - initial contribution and API. * @author Simon Kaufmann - initial contribution and API.
* *
*/ */
@NonNullByDefault
public class ListenSpecImpl extends AbstractSpec implements InboundSpec { public class ListenSpecImpl extends AbstractSpec implements InboundSpec {
private final List<GroupAddress> listenAddresses; private final List<GroupAddress> listenAddresses;

View File

@ -244,7 +244,7 @@ public abstract class AbstractKNXClient implements NetworkLinkListener, KNXClien
}); });
} }
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) { if (target != null && lastWill != null) {
lastWill.accept(target); lastWill.accept(target);
} }
@ -392,7 +392,8 @@ public abstract class AbstractKNXClient implements NetworkLinkListener, KNXClien
@Override @Override
public boolean isConnected() { public boolean isConnected() {
return link != null && link.isOpen(); final var tmpLink = link;
return tmpLink != null && tmpLink.isOpen();
} }
@Override @Override

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.binding.knx.internal.client; package org.openhab.binding.knx.internal.client;
import org.eclipse.jdt.annotation.NonNullByDefault;
import tuwien.auto.calimero.KNXException; import tuwien.auto.calimero.KNXException;
import tuwien.auto.calimero.knxnetip.KNXnetIPConnection; import tuwien.auto.calimero.knxnetip.KNXnetIPConnection;
import tuwien.auto.calimero.link.KNXNetworkLinkIP; import tuwien.auto.calimero.link.KNXNetworkLinkIP;
@ -24,6 +26,7 @@ import tuwien.auto.calimero.link.medium.KNXMediumSettings;
* @author Simon Kaufmann - initial contribution and API * @author Simon Kaufmann - initial contribution and API
* *
*/ */
@NonNullByDefault
public class CustomKNXNetworkLinkIP extends KNXNetworkLinkIP { public class CustomKNXNetworkLinkIP extends KNXNetworkLinkIP {
public static final int TUNNELING = KNXNetworkLinkIP.TUNNELING; public static final int TUNNELING = KNXNetworkLinkIP.TUNNELING;

View File

@ -100,7 +100,7 @@ public class DeviceInspector {
OPERATION_TIMEOUT); OPERATION_TIMEOUT);
if ((elements == null ? 0 : toUnsigned(elements)) == 1) { if ((elements == null ? 0 : toUnsigned(elements)) == 1) {
Thread.sleep(OPERATION_INTERVAL); 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))); DEVICE_OBJECT, PID.MANUFACTURER_ID, 1, 1, false, OPERATION_TIMEOUT)));
Thread.sleep(OPERATION_INTERVAL); Thread.sleep(OPERATION_INTERVAL);
String serialNo = toHex(getClient().readDeviceProperties(address, DEVICE_OBJECT, PID.SERIAL_NUMBER, 1, String serialNo = toHex(getClient().readDeviceProperties(address, DEVICE_OBJECT, PID.SERIAL_NUMBER, 1,
@ -112,7 +112,7 @@ public class DeviceInspector {
String firmwareRevision = Integer.toString(toUnsigned(getClient().readDeviceProperties(address, String firmwareRevision = Integer.toString(toUnsigned(getClient().readDeviceProperties(address,
DEVICE_OBJECT, PID.FIRMWARE_REVISION, 1, 1, false, OPERATION_TIMEOUT))); DEVICE_OBJECT, PID.FIRMWARE_REVISION, 1, 1, false, OPERATION_TIMEOUT)));
ret.put(MANUFACTURER_NAME, ManufacturerID); ret.put(MANUFACTURER_NAME, manufacturerID);
if (serialNo != null) { if (serialNo != null) {
ret.put(MANUFACTURER_SERIAL_NO, serialNo); ret.put(MANUFACTURER_SERIAL_NO, serialNo);
} }
@ -121,7 +121,7 @@ public class DeviceInspector {
} }
ret.put(MANUFACTURER_FIRMWARE_REVISION, firmwareRevision); ret.put(MANUFACTURER_FIRMWARE_REVISION, firmwareRevision);
logger.debug("Identified device {} as a {}, type {}, revision {}, serial number {}", address, logger.debug("Identified device {} as a {}, type {}, revision {}, serial number {}", address,
ManufacturerID, hardwareType, firmwareRevision, serialNo); manufacturerID, hardwareType, firmwareRevision, serialNo);
} else { } else {
logger.debug("The KNX device with address {} does not expose a Device Object", address); logger.debug("The KNX device with address {} does not expose a Device Object", address);
} }

View File

@ -15,7 +15,7 @@ package org.openhab.binding.knx.internal.client;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.concurrent.ScheduledExecutorService; 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.openhab.core.thing.ThingUID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,6 +33,7 @@ import tuwien.auto.calimero.link.medium.TPSettings;
* @author Simon Kaufmann - initial contribution and API. * @author Simon Kaufmann - initial contribution and API.
* *
*/ */
@NonNullByDefault
public class SerialClient extends AbstractKNXClient { public class SerialClient extends AbstractKNXClient {
private final Logger logger = LoggerFactory.getLogger(SerialClient.class); private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
@ -48,7 +49,7 @@ public class SerialClient extends AbstractKNXClient {
} }
@Override @Override
protected @NonNull KNXNetworkLink establishConnection() throws KNXException, InterruptedException { protected KNXNetworkLink establishConnection() throws KNXException, InterruptedException {
try { try {
RXTXVersion.getVersion(); RXTXVersion.getVersion();
logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}.", serialPort); logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}.", serialPort);
@ -59,12 +60,13 @@ public class SerialClient extends AbstractKNXClient {
"The serial FT1.2 KNX connection requires the RXTX libraries to be available, but they could not be found!", "The serial FT1.2 KNX connection requires the RXTX libraries to be available, but they could not be found!",
e); e);
} catch (KNXException 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"); StringBuilder sb = new StringBuilder("Available ports are:\n");
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers(); Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) { while (portList.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) portList.nextElement(); 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(id.getName());
sb.append("\n"); sb.append("\n");
} }

View File

@ -14,19 +14,20 @@ package org.openhab.binding.knx.internal.config;
import java.math.BigDecimal; 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 * @author Simon Kaufmann - initial contribution and API
* *
*/ */
@NonNullByDefault
public class BridgeConfiguration { public class BridgeConfiguration {
private int autoReconnectPeriod; private int autoReconnectPeriod = 0;
private BigDecimal readingPause; private BigDecimal readingPause = BigDecimal.valueOf(0);
private BigDecimal readRetriesLimit; private BigDecimal readRetriesLimit = BigDecimal.valueOf(0);
private BigDecimal responseTimeout; private BigDecimal responseTimeout = BigDecimal.valueOf(0);
public int getAutoReconnectPeriod() { public int getAutoReconnectPeriod() {
return autoReconnectPeriod; return autoReconnectPeriod;

View File

@ -14,18 +14,21 @@ package org.openhab.binding.knx.internal.config;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* Configuration object for the device thing handler. * Configuration object for the device thing handler.
* *
* @author Karel Goderis - Initial contribution * @author Karel Goderis - Initial contribution
* @author Simon Kaufmann - refactoring & cleanup * @author Simon Kaufmann - refactoring & cleanup
*/ */
@NonNullByDefault
public class DeviceConfig { public class DeviceConfig {
private String address; private String address = "";
private boolean fetch; private boolean fetch = false;
private BigDecimal pingInterval; private BigDecimal pingInterval = BigDecimal.valueOf(0);
private BigDecimal readInterval; private BigDecimal readInterval = BigDecimal.valueOf(0);
public String getAddress() { public String getAddress() {
return address; return address;

View File

@ -14,20 +14,23 @@ package org.openhab.binding.knx.internal.config;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* IP Bridge handler configuration object. * IP Bridge handler configuration object.
* *
* @author Simon Kaufmann - initial contribution and API * @author Simon Kaufmann - initial contribution and API
* *
*/ */
@NonNullByDefault
public class IPBridgeConfiguration extends BridgeConfiguration { public class IPBridgeConfiguration extends BridgeConfiguration {
private boolean useNAT; private boolean useNAT = false;
private String type; private String type = "";
private String ipAddress; private String ipAddress = "";
private BigDecimal portNumber; private BigDecimal portNumber = BigDecimal.valueOf(0);
private String localIp; private String localIp = "";
private String localSourceAddr; private String localSourceAddr = "";
public Boolean getUseNAT() { public Boolean getUseNAT() {
return useNAT; return useNAT;

View File

@ -12,15 +12,18 @@
*/ */
package org.openhab.binding.knx.internal.config; package org.openhab.binding.knx.internal.config;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* Serial Bridge configuration object. * Serial Bridge configuration object.
* *
* @author Simon Kaufmann - initial contribution and API. * @author Simon Kaufmann - initial contribution and API.
* *
*/ */
@NonNullByDefault
public class SerialBridgeConfiguration extends BridgeConfiguration { public class SerialBridgeConfiguration extends BridgeConfiguration {
private String serialPort; private String serialPort = "";
public String getSerialPort() { public String getSerialPort() {
return serialPort; return serialPort;

View File

@ -55,8 +55,8 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
ThingUID bridgeUID) { ThingUID bridgeUID) {
if (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) { if (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) {
ThingUID IPBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration); ThingUID ipBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration);
return super.createThing(thingTypeUID, configuration, IPBridgeUID, null); return super.createThing(thingTypeUID, configuration, ipBridgeUID, null);
} }
if (THING_TYPE_SERIAL_BRIDGE.equals(thingTypeUID)) { if (THING_TYPE_SERIAL_BRIDGE.equals(thingTypeUID)) {
ThingUID serialBridgeUID = getSerialBridgeThingUID(thingTypeUID, thingUID, configuration); ThingUID serialBridgeUID = getSerialBridgeThingUID(thingTypeUID, thingUID, configuration);

View File

@ -19,7 +19,6 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.client.DeviceInspector; import org.openhab.binding.knx.internal.client.DeviceInspector;
@ -118,7 +117,7 @@ public abstract class AbstractKNXThingHandler extends BaseThingHandler implement
} }
@Override @Override
public void bridgeStatusChanged(@NonNull ThingStatusInfo bridgeStatusInfo) { public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) { if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
attachToClient(); attachToClient();
} else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) { } else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
@ -175,7 +174,7 @@ public abstract class AbstractKNXThingHandler extends BaseThingHandler implement
} }
DeviceConfig config = getConfigAs(DeviceConfig.class); DeviceConfig config = getConfigAs(DeviceConfig.class);
try { try {
if (config.getAddress() != null && !config.getAddress().isEmpty()) { if (!config.getAddress().isEmpty()) {
updateStatus(ThingStatus.UNKNOWN); updateStatus(ThingStatus.UNKNOWN);
address = new IndividualAddress(config.getAddress()); address = new IndividualAddress(config.getAddress());
@ -200,12 +199,14 @@ public abstract class AbstractKNXThingHandler extends BaseThingHandler implement
} }
protected void detachFromClient() { protected void detachFromClient() {
if (pollingJob != null) { final var pollingJobSynced = pollingJob;
pollingJob.cancel(true); if (pollingJobSynced != null) {
pollingJobSynced.cancel(true);
pollingJob = null; pollingJob = null;
} }
if (descriptionJob != null) { final var descriptionJobSynced = descriptionJob;
descriptionJob.cancel(true); if (descriptionJobSynced != null) {
descriptionJobSynced.cancel(true);
descriptionJob = null; descriptionJob = null;
} }
cancelReadFutures(); cancelReadFutures();

View File

@ -12,9 +12,12 @@
*/ */
package org.openhab.binding.knx.internal.handler; package org.openhab.binding.knx.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* @author Karel Goderis - Initial contribution * @author Karel Goderis - Initial contribution
*/ */
@NonNullByDefault
public class DeviceConstants { public class DeviceConstants {
private DeviceConstants() { private DeviceConstants() {

View File

@ -105,7 +105,7 @@ public class DeviceThingHandler extends AbstractKNXThingHandler {
private void cancelChannelFutures() { private void cancelChannelFutures() {
for (ScheduledFuture<?> future : channelFutures.values()) { for (ScheduledFuture<?> future : channelFutures.values()) {
if (future != null && !future.isDone()) { if (!future.isDone()) {
future.cancel(true); future.cancel(true);
} }
} }
@ -121,7 +121,7 @@ public class DeviceThingHandler extends AbstractKNXThingHandler {
@Override @Override
protected void cancelReadFutures() { protected void cancelReadFutures() {
for (ScheduledFuture<?> future : readFutures.values()) { for (ScheduledFuture<?> future : readFutures.values()) {
if (future != null && !future.isDone()) { if (!future.isDone()) {
future.cancel(true); future.cancel(true);
} }
} }

View File

@ -72,11 +72,11 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
boolean useNAT = false; boolean useNAT = false;
int ipConnectionType; int ipConnectionType;
if (MODE_TUNNEL.equalsIgnoreCase(connectionTypeString)) { if (MODE_TUNNEL.equalsIgnoreCase(connectionTypeString)) {
useNAT = config.getUseNAT() != null ? config.getUseNAT() : false; useNAT = config.getUseNAT();
ipConnectionType = CustomKNXNetworkLinkIP.TUNNELING; ipConnectionType = CustomKNXNetworkLinkIP.TUNNELING;
} else if (MODE_ROUTER.equalsIgnoreCase(connectionTypeString)) { } else if (MODE_ROUTER.equalsIgnoreCase(connectionTypeString)) {
useNAT = false; useNAT = false;
if (ip == null || ip.isEmpty()) { if (ip.isEmpty()) {
ip = KNXBindingConstants.DEFAULT_MULTICAST_IP; ip = KNXBindingConstants.DEFAULT_MULTICAST_IP;
} }
ipConnectionType = CustomKNXNetworkLinkIP.ROUTING; ipConnectionType = CustomKNXNetworkLinkIP.ROUTING;
@ -86,13 +86,8 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
connectionTypeString)); connectionTypeString));
return; 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); localEndPoint = new InetSocketAddress(config.getLocalIp(), 0);
} else { } else {
localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0); localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0);
@ -103,14 +98,18 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
thing.getUID(), config.getResponseTimeout().intValue(), config.getReadingPause().intValue(), thing.getUID(), config.getResponseTimeout().intValue(), config.getReadingPause().intValue(),
config.getReadRetriesLimit().intValue(), getScheduler(), this); config.getReadRetriesLimit().intValue(), getScheduler(), this);
client.initialize(); final var tmpClient = client;
if (tmpClient != null) {
tmpClient.initialize();
}
} }
@Override @Override
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
if (client != null) { final var tmpClient = client;
client.dispose(); if (tmpClient != null) {
tmpClient.dispose();
client = null; client = null;
} }
} }

View File

@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.*;
import java.util.Collections; import java.util.Collections;
import java.util.Set; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -26,17 +26,19 @@ import org.junit.jupiter.api.Test;
* @author Simon Kaufmann - initial contribution and API. * @author Simon Kaufmann - initial contribution and API.
* *
*/ */
@NonNullByDefault
public class KNXChannelTypeTest { public class KNXChannelTypeTest {
private KNXChannelType ct; private KNXChannelType ct = new MyKNXChannelType("");
@BeforeEach @BeforeEach
public void setup() { public void setup() {
ct = new MyKNXChannelType(""); ct = new MyKNXChannelType("");
} }
@SuppressWarnings("null")
@Test @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"); ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
assertEquals("5.001", res.getDPT()); assertEquals("5.001", res.getDPT());
@ -46,8 +48,9 @@ public class KNXChannelTypeTest {
assertEquals(2, res.getReadGAs().size()); assertEquals(2, res.getReadGAs().size());
} }
@SuppressWarnings("null")
@Test @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"); ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
assertEquals("5.001", res.getDPT()); assertEquals("5.001", res.getDPT());
@ -57,8 +60,9 @@ public class KNXChannelTypeTest {
assertEquals(0, res.getReadGAs().size()); assertEquals(0, res.getReadGAs().size());
} }
@SuppressWarnings("null")
@Test @Test
public void testParse_withoutDPT_single_withoutRead() { public void testParseWithoutDptSingleWithoutRead() {
ChannelConfiguration res = ct.parse("1/3/22"); ChannelConfiguration res = ct.parse("1/3/22");
assertNull(res.getDPT()); assertNull(res.getDPT());
@ -68,8 +72,9 @@ public class KNXChannelTypeTest {
assertEquals(0, res.getReadGAs().size()); assertEquals(0, res.getReadGAs().size());
} }
@SuppressWarnings("null")
@Test @Test
public void testParse_withoutDPT_single_witRead() { public void testParseWithoutDptSingleWitRead() {
ChannelConfiguration res = ct.parse("<1/3/22"); ChannelConfiguration res = ct.parse("<1/3/22");
assertNull(res.getDPT()); assertNull(res.getDPT());
@ -79,16 +84,18 @@ public class KNXChannelTypeTest {
assertEquals(1, res.getReadGAs().size()); assertEquals(1, res.getReadGAs().size());
} }
@SuppressWarnings("null")
@Test @Test
public void testParse_twoLevel() { public void testParseTwoLevel() {
ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025"); ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
assertEquals("3/1024", res.getMainGA().getGA()); assertEquals("3/1024", res.getMainGA().getGA());
assertEquals(2, res.getListenGAs().size()); assertEquals(2, res.getListenGAs().size());
assertEquals(2, res.getReadGAs().size()); assertEquals(2, res.getReadGAs().size());
} }
@SuppressWarnings("null")
@Test @Test
public void testParse_freeLevel() { public void testParseFreeLevel() {
ChannelConfiguration res = ct.parse("5.001:<4610+<4611"); ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
assertEquals("4610", res.getMainGA().getGA()); assertEquals("4610", res.getMainGA().getGA());
assertEquals(2, res.getListenGAs().size()); assertEquals(2, res.getListenGAs().size());
@ -101,12 +108,12 @@ public class KNXChannelTypeTest {
} }
@Override @Override
protected @NonNull Set<@NonNull String> getAllGAKeys() { protected Set<String> getAllGAKeys() {
return Collections.emptySet(); return Collections.emptySet();
} }
@Override @Override
protected @NonNull String getDefaultDPT(@NonNull String gaConfigKey) { protected String getDefaultDPT(String gaConfigKey) {
return ""; return "";
} }
} }

View File

@ -14,6 +14,7 @@ package org.openhab.binding.knx.internal.dpt;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
@ -22,10 +23,11 @@ import org.openhab.core.library.types.DecimalType;
* @author Simon Kaufmann - initial contribution and API * @author Simon Kaufmann - initial contribution and API
* *
*/ */
@NonNullByDefault
public class KNXCoreTypeMapperTest { public class KNXCoreTypeMapperTest {
@Test @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"), "17.001"));
assertEquals("3", new KNXCoreTypeMapper().toDPTValue(new DecimalType("3.0"), "17.001")); assertEquals("3", new KNXCoreTypeMapper().toDPTValue(new DecimalType("3.0"), "17.001"));
} }