Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[knx] Reduce compiler warnings #12518

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Set;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
Expand All @@ -26,6 +27,7 @@
*
* @author Karel Goderis - Initial contribution
*/
@NonNullByDefault
public class KNXBindingConstants {

public static final String BINDING_ID = "knx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
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
* between openHAB and KNX.
* 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
Expand All @@ -45,7 +44,8 @@ public interface KNXTypeMapper {
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

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;
Expand Down Expand Up @@ -57,7 +55,8 @@ protected final GroupAddress toGroupAddress(GroupAddressConfiguration ga) {
/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

Expand All @@ -28,6 +29,7 @@
* @author Simon Kaufmann - initial contribution and API.
*
*/
@NonNullByDefault
public class ListenSpecImpl extends AbstractSpec implements InboundSpec {

private final List<GroupAddress> listenAddresses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void releaseConnection() {
});
}

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);
}
Expand Down Expand Up @@ -392,7 +392,8 @@ public final boolean unregisterGroupAddressListener(GroupAddressListener listene

@Override
public boolean isConnected() {
return link != null && link.isOpen();
final var tmpLink = link;
return tmpLink != null && tmpLink.isOpen();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
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;
Expand All @@ -24,6 +26,7 @@
* @author Simon Kaufmann - initial contribution and API
*
*/
@NonNullByDefault
public class CustomKNXNetworkLinkIP extends KNXNetworkLinkIP {

public static final int TUNNELING = KNXNetworkLinkIP.TUNNELING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
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,
Expand All @@ -112,7 +112,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
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);
}
Expand All @@ -121,7 +121,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
}
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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;
Expand All @@ -33,6 +33,7 @@
* @author Simon Kaufmann - initial contribution and API.
*
*/
@NonNullByDefault
public class SerialClient extends AbstractKNXClient {

private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
Expand All @@ -48,7 +49,7 @@ public SerialClient(int autoReconnectPeriod, ThingUID thingUID, int responseTime
}

@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);
Expand All @@ -59,12 +60,13 @@ public SerialClient(int autoReconnectPeriod, ThingUID thingUID, int responseTime
"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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -118,7 +117,7 @@ protected final void restart() {
}

@Override
public void bridgeStatusChanged(@NonNull ThingStatusInfo bridgeStatusInfo) {
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
attachToClient();
} else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
Expand Down Expand Up @@ -175,7 +174,7 @@ protected void attachToClient() {
}
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());

Expand All @@ -200,12 +199,14 @@ protected void attachToClient() {
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
package org.openhab.binding.knx.internal.handler;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* @author Karel Goderis - Initial contribution
*/
@NonNullByDefault
public class DeviceConstants {

private DeviceConstants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void dispose() {

private void cancelChannelFutures() {
for (ScheduledFuture<?> future : channelFutures.values()) {
if (future != null && !future.isDone()) {
if (!future.isDone()) {
future.cancel(true);
}
}
Expand All @@ -121,7 +121,7 @@ private void freeGroupAdresses() {
@Override
protected void cancelReadFutures() {
for (ScheduledFuture<?> future : readFutures.values()) {
if (future != null && !future.isDone()) {
if (!future.isDone()) {
future.cancel(true);
}
}
Expand Down
Loading