diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ACommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ACommand.java index 051ee41e62cda..23d9b314a55f1 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ACommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ACommand.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link ACommand} deletes the device and room configuration from the Cube. * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class ACommand extends CubeCommand { @Override diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CCommand.java index 4fcfe81cd0e8f..49d3fa450e52d 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CCommand.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link C_CubeCommand} to request configuration of a new MAX! device after inclusion. * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class CCommand extends CubeCommand { private final String rfAddress; diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CubeCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CubeCommand.java index 7c9ce357af9fc..ea7c51d9bddf5 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CubeCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/CubeCommand.java @@ -12,12 +12,15 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * {@link CubeCommand} is the base class for commands to be send to the MAX! Cube. * * @author Marcel Verpaalen - Initial contribution * */ +@NonNullByDefault public abstract class CubeCommand { /** diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/FCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/FCommand.java index d098cac6f0741..33aea328db341 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/FCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/FCommand.java @@ -12,11 +12,15 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + /** * The {@link F_CubeCommand} is used to query and update the NTP servers used by the Cube. * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class FCommand extends CubeCommand { private String ntpServer1 = ""; @@ -31,7 +35,7 @@ public FCommand() { /** * Updates the Cube the NTP info */ - public FCommand(String ntpServer1, String ntpServer2) { + public FCommand(@Nullable String ntpServer1, @Nullable String ntpServer2) { this.ntpServer1 = ntpServer1 != null ? ntpServer1 : ""; this.ntpServer2 = ntpServer2 != null ? ntpServer2 : ""; } @@ -44,7 +48,6 @@ public String getCommandString() { } else { servers = ntpServer1 + ntpServer2; } - return "f:" + servers + '\r' + '\n'; } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/LCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/LCommand.java index bb9e96b38973f..417550a095532 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/LCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/LCommand.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link LCommand} request a status update for MAX! devices. * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class LCommand extends CubeCommand { @Override diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java index 6e08679e47be1..14c85094725e3 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.net.util.Base64; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.Device; import org.openhab.binding.max.internal.device.RoomInformation; @@ -33,6 +34,7 @@ * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class MCommand extends CubeCommand { private final Logger logger = LoggerFactory.getLogger(MCommand.class); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/NCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/NCommand.java index 2b58beb6bedf6..a2046e57bb3cc 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/NCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/NCommand.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link N_CubeCommand} starts the inclusion mode for new MAX! devices. - * + * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class NCommand extends CubeCommand { // Example n:003c = start inclusion, timeout 003c = 60 sec diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/QCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/QCommand.java index b1c885fff7c86..ddc1357668591 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/QCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/QCommand.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link QCommand} Quits the connection to the MAX! Cube. * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class QCommand extends CubeCommand { @Override @@ -26,6 +29,6 @@ public String getCommandString() { @Override public String getReturnStrings() { - return null; + return ""; } } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java index 9b15010f92704..e7b5c98a5a230 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java @@ -13,6 +13,7 @@ package org.openhab.binding.max.internal.command; import org.apache.commons.net.util.Base64; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.ThermostatModeType; @@ -22,6 +23,7 @@ * @author Andreas Heil (info@aheil.de) - Initial contribution * @author Marcel Verpaalen - OH2 update + simplification */ +@NonNullByDefault public class SCommand extends CubeCommand { private static final String BASE_STRING_S = "000040000000"; // for single devices diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java index 7e01862e059a5..9d118a7752c59 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java @@ -13,6 +13,7 @@ package org.openhab.binding.max.internal.command; import org.apache.commons.net.util.Base64; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.max.internal.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,13 +23,14 @@ * * @author Marcel Verpaalen - Initial contribution */ +@NonNullByDefault public class SConfigCommand extends CubeCommand { - private String baseString; + private String baseString = ""; private final String rfAddress; private final int roomId; - private byte[] commandBytes; + private byte[] commandBytes = new byte[0]; private final Logger logger = LoggerFactory.getLogger(SConfigCommand.class); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java index 486f8a88fbda0..b37f003f48233 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java @@ -17,6 +17,7 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.net.util.Base64; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.max.internal.Utils; /** @@ -24,6 +25,7 @@ * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class TCommand extends CubeCommand { private static final int FORCE_UPDATE = 1; diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/UdpCubeCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/UdpCubeCommand.java index 35ad91e50a69f..1747735361204 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/UdpCubeCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/UdpCubeCommand.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.max.internal.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +36,7 @@ * * @author Marcel Verpaalen - Initial contribution */ +@NonNullByDefault public class UdpCubeCommand { private static final String MAXCUBE_COMMAND_STRING = "eQ3Max*\0"; @@ -45,9 +48,10 @@ public class UdpCubeCommand { private final UdpCommandType commandType; private final String serialNumber; private Map commandResponse = new HashMap<>(); + @Nullable private String ipAddress; - public UdpCubeCommand(UdpCommandType commandType, String serialNumber) { + public UdpCubeCommand(UdpCommandType commandType, @Nullable String serialNumber) { this.commandType = commandType; if (serialNumber == null || serialNumber.isEmpty()) { this.serialNumber = "**********"; @@ -168,7 +172,7 @@ private void receiveUdpCommandResponse() { * @param ipAddress IP address of the MAX! Cube * */ - private void sendUdpCommand(String commandString, String ipAddress) { + private void sendUdpCommand(String commandString, @Nullable String ipAddress) { DatagramSocket bcSend = null; try { bcSend = new DatagramSocket(); @@ -184,7 +188,6 @@ private void sendUdpCommand(String commandString, String ipAddress) { continue; } for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) { - InetAddress[] broadcast = new InetAddress[3]; if (ipAddress != null && !ipAddress.isEmpty()) { broadcast[0] = InetAddress.getByName(ipAddress); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ZCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ZCommand.java index 93e9a4b3a7dde..bd63fd598b857 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ZCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/ZCommand.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.max.internal.command; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.max.internal.Utils; /** @@ -19,6 +20,7 @@ * * @author Marcel Verpaalen - Initial Contribution */ +@NonNullByDefault public class ZCommand extends CubeCommand { public enum WakeUpType { diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java index 4f5e1a7cc43f7..c2b3030b010b4 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/MaxCubeBridgeHandler.java @@ -573,7 +573,7 @@ private synchronized boolean sendCubeCommand(CubeCommand command) { writer.write(command.getCommandString()); logger.trace("Write string to Max! Cube {}: {}", ipAddress, command.getCommandString()); writer.flush(); - if (command.getReturnStrings() != null) { + if (!command.getReturnStrings().isEmpty()) { readLines(command.getReturnStrings()); } else { socketClose(); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/SendCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/SendCommand.java index 55942ea9ae550..c39b3f1b35120 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/SendCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/handler/SendCommand.java @@ -12,7 +12,8 @@ */ package org.openhab.binding.max.internal.handler; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.types.Command; import org.openhab.binding.max.internal.command.CubeCommand; @@ -22,14 +23,15 @@ * * @author Marcel Verpaalen - Initial contribution */ +@NonNullByDefault public final class SendCommand { private int id; private static int commandId = -1; - private ChannelUID channelUID; - private Command command; - private CubeCommand cubeCommand; + private @Nullable ChannelUID channelUID; + private @Nullable Command command; + private @Nullable CubeCommand cubeCommand; private String serialNumber; private String key; private String commandText; @@ -41,7 +43,7 @@ public SendCommand(String serialNumber, ChannelUID channelUID, Command command) this.channelUID = channelUID; this.command = command; key = getKey(serialNumber, channelUID); - this.setCommandText(command.toString()); + this.commandText = command.toString(); } public SendCommand(String serialNumber, CubeCommand cubeCommand, String commandText) { @@ -50,7 +52,7 @@ public SendCommand(String serialNumber, CubeCommand cubeCommand, String commandT this.serialNumber = serialNumber; this.cubeCommand = cubeCommand; key = getKey(serialNumber, cubeCommand); - this.setCommandText(commandText); + this.commandText = commandText; } /** @@ -82,7 +84,7 @@ public int getId() { return id; } - public ChannelUID getChannelUID() { + public @Nullable ChannelUID getChannelUID() { return channelUID; } @@ -91,7 +93,7 @@ public void setChannelUID(ChannelUID channelUID) { key = getKey(serialNumber, channelUID); } - public Command getCommand() { + public @Nullable Command getCommand() { return command; } @@ -99,7 +101,7 @@ public void setCommand(Command command) { this.command = command; } - public CubeCommand getCubeCommand() { + public @Nullable CubeCommand getCubeCommand() { return cubeCommand; } @@ -109,7 +111,10 @@ public String getDeviceSerial() { public void setDeviceSerial(String device) { this.serialNumber = device; - key = getKey(serialNumber, channelUID); + final ChannelUID channelUID = this.channelUID; + if (channelUID != null) { + key = getKey(serialNumber, channelUID); + } } public String getCommandText() { @@ -122,8 +127,10 @@ public void setCommandText(String commandText) { @Override public String toString() { - return new ToStringBuilder(this).append("id", id).append("channelUID", channelUID).append("command", command) - .append("cubeCommand", cubeCommand).append("serialNumber", serialNumber).append("key", key) - .append("commandText", commandText).toString(); + StringBuilder sb = new StringBuilder(); + return sb.append("id: ").append(id).append(", channelUID: ").append(channelUID).append(", command: ") + .append(command).append(", cubeCommand: ").append(cubeCommand).append(", serialNumber: ") + .append(serialNumber).append(", key: ").append(key).append(", commandText: ").append(commandText) + .toString(); } }