]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] Fix SAT warnings (#14052)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Sat, 24 Dec 2022 11:11:28 +0000 (12:11 +0100)
committerGitHub <noreply@github.com>
Sat, 24 Dec 2022 11:11:28 +0000 (12:11 +0100)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
bundles/org.openhab.binding.knx/README.md
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/WriteSpecImpl.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/ReadDatapoint.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/KNXCoreTypeMapper.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/factory/KNXHandlerFactory.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/IPBridgeThingHandler.java

index ca316ee591fcdc20c2dc292b67889db22bf04378..6ac60a148577dac54892ef3713b6b356a8ddd655 100644 (file)
@@ -223,9 +223,7 @@ It is created by the ETS tool and cannot be changed via the ETS user interface.
 For _Secure tunneling_ with a Secure IP Interface (or a router in tunneling mode), more parameters are required.
 A unique device authentication key, and a specific tunnel identifier and password need to be available.
 
-- All information can be looked up in ETS and provided separately: `tunnelDeviceAuthentication`, `tunnelUserPassword`.
-`tunnelUserId` is a number which is not directly visible in ETS, but can be looked up in keyring export or deduced (typically 2 for the first tunnel of a device, 3 for the second one, ...).
-`tunnelUserPasswort` is set in ETS in the properties of the tunnel (below the IP interface you will see the different tunnels listed) denoted as "Password". `tunnelDeviceAuthentication` is set in the properties of the IP interface itself, check for a tab "IP" and a description "Authentication Code".
+- All information can be looked up in ETS and provided separately: `tunnelDeviceAuthentication`, `tunnelUserPassword`. `tunnelUserId` is a number which is not directly visible in ETS, but can be looked up in keyring export or deduced (typically 2 for the first tunnel of a device, 3 for the second one, ...). `tunnelUserPasswort` is set in ETS in the properties of the tunnel (below the IP interface you will see the different tunnels listed) denoted as "Password". `tunnelDeviceAuthentication` is set in the properties of the IP interface itself, check for a tab "IP" and a description "Authentication Code".
 
 ### KNX Data Secure
 
index 1515c5ac4cdbf89efcd6851f5a77f6959b3d8111..00b4f45f7c68be66de946c25fba919df1f8ef155 100644 (file)
@@ -12,6 +12,7 @@
  */
 package org.openhab.binding.knx.internal.channel;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.knx.internal.client.OutboundSpec;
 import org.openhab.core.types.Type;
@@ -25,6 +26,7 @@ import tuwien.auto.calimero.KNXFormatException;
  * @author Simon Kaufmann - initial contribution and API.
  *
  */
+@NonNullByDefault
 public class WriteSpecImpl extends AbstractSpec implements OutboundSpec {
 
     private final Type type;
index 628e81de50b635fb9b7ea4b4645eae37c70a3b03..b9e6558b248012a5313b6ab49c3af5e279c84594 100644 (file)
@@ -12,6 +12,9 @@
  */
 package org.openhab.binding.knx.internal.client;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
 import tuwien.auto.calimero.datapoint.Datapoint;
 
 /**
@@ -19,6 +22,7 @@ import tuwien.auto.calimero.datapoint.Datapoint;
  *
  * @author Karel Goderis - Initial contribution
  */
+@NonNullByDefault
 public class ReadDatapoint {
 
     private final Datapoint datapoint;
@@ -56,7 +60,7 @@ public class ReadDatapoint {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(@Nullable Object obj) {
         if (this == obj) {
             return true;
         }
@@ -66,14 +70,8 @@ public class ReadDatapoint {
         if (getClass() != obj.getClass()) {
             return false;
         }
+        @Nullable
         ReadDatapoint other = (ReadDatapoint) obj;
-        if (datapoint == null) {
-            if (other.datapoint != null) {
-                return false;
-            }
-        } else if (!datapoint.getMainAddress().equals(other.datapoint.getMainAddress())) {
-            return false;
-        }
-        return true;
+        return datapoint.getMainAddress().equals(other.datapoint.getMainAddress());
     }
 }
index 1f32068d2b9f37a41a03a28ebe39483d7a8ccea4..481f418f4700bb1e6ab6402dda0878397a6aee00 100644 (file)
@@ -26,6 +26,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.knx.internal.KNXTypeMapper;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
@@ -84,11 +86,12 @@ import tuwien.auto.calimero.dptxlator.TranslatorTypes;
  * If for a 'MainType' there is currently no specific mapping registered,
  * you can find a commented example line, with it's correct 'DPTXlator' class.
  *
- * @author Kai Kreuzer
- * @author Volker Daube
- * @author Jan N. Klug
+ * @author Kai Kreuzer - initial contribution
+ * @author Volker Daube - improvements
+ * @author Jan N. Klug - improvements
  * @author Helmut Lehmeyer - Java8, generic DPT Mapper
  */
+@NonNullByDefault
 @Component
 public class KNXCoreTypeMapper implements KNXTypeMapper {
 
@@ -735,7 +738,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
     }
 
     @Override
-    public String toDPTValue(Type type, String dptID) {
+    public @Nullable String toDPTValue(Type type, @Nullable String dptID) {
         DPT dpt;
         int mainNumber = getMainNumber(dptID);
         if (mainNumber == -1) {
@@ -838,7 +841,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
     }
 
     @Override
-    public Type toType(Datapoint datapoint, byte[] data) {
+    public @Nullable Type toType(Datapoint datapoint, byte[] data) {
         try {
             DPTXlator translator = TranslatorTypes.createTranslator(datapoint.getMainNumber(), datapoint.getDPT());
             translator.setData(data);
@@ -996,7 +999,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
 
             if (typeClass.equals(DateTimeType.class)) {
                 String date = formatDateTime(value, datapoint.getDPT());
-                if ((date == null) || (date.isEmpty())) {
+                if (date.isEmpty()) {
                     logger.debug("toType: KNX clock msg ignored: date object null or empty {}.", date);
                     return null;
                 } else {
@@ -1033,7 +1036,8 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
      * @return the openHAB type (command or state) class or {@code null} if the datapoint type id is not supported.
      */
     @Override
-    public Class<? extends Type> toTypeClass(String dptId) {
+    public @Nullable Class<? extends Type> toTypeClass(@Nullable String dptId) {
+        @Nullable
         Class<? extends Type> ohClass = dptTypeMap.get(dptId);
         if (ohClass == null) {
             int mainNumber = getMainNumber(dptId);
@@ -1052,7 +1056,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
      * @param typeClass the openHAB type class
      * @return the datapoint type id
      */
-    public String toDPTid(Class<? extends Type> typeClass) {
+    public @Nullable String toDPTid(Class<? extends Type> typeClass) {
         return defaultDptMap.get(typeClass);
     }
 
@@ -1114,7 +1118,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
      * @throws IllegalArgumentException if none of the datapoint types DPT_DATE or
      *             DPT_TIMEOFDAY has been used.
      */
-    private static String formatDateTime(DateTimeType dateType, String dpt) {
+    private static String formatDateTime(DateTimeType dateType, @Nullable String dpt) {
         if (DPTXlatorDate.DPT_DATE.getID().equals(dpt)) {
             return dateType.format("%tF");
         } else if (DPTXlatorTime.DPT_TIMEOFDAY.getID().equals(dpt)) {
@@ -1132,7 +1136,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
      * @param dptID String with DPT ID
      * @return sub number or -1
      */
-    private int getSubNumber(String dptID) {
+    private int getSubNumber(@Nullable String dptID) {
         int result = -1;
         if (dptID == null) {
             throw new IllegalArgumentException("Parameter dptID cannot be null");
@@ -1159,7 +1163,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
      * @param dptID String with DPT ID
      * @return main number or -1
      */
-    private int getMainNumber(String dptID) {
+    private int getMainNumber(@Nullable String dptID) {
         int result = -1;
         if (dptID == null) {
             throw new IllegalArgumentException("Parameter dptID cannot be null");
index 913786aeea9481d95200cba139c33eeeca5b5335..b93a7d629bc8c2fe76a8d9bda11b31468bad8d82 100644 (file)
@@ -17,6 +17,8 @@ import static org.openhab.binding.knx.internal.KNXBindingConstants.*;
 import java.util.Arrays;
 import java.util.Collection;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.knx.internal.handler.DeviceThingHandler;
 import org.openhab.binding.knx.internal.handler.IPBridgeThingHandler;
 import org.openhab.binding.knx.internal.handler.SerialBridgeThingHandler;
@@ -42,12 +44,14 @@ import org.osgi.service.component.annotations.Reference;
  *
  * @author Simon Kaufmann - Initial contribution and API
  */
+@NonNullByDefault
 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.knx")
 public class KNXHandlerFactory extends BaseThingHandlerFactory {
 
     public static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Arrays.asList(THING_TYPE_DEVICE,
             THING_TYPE_IP_BRIDGE, THING_TYPE_SERIAL_BRIDGE);
 
+    @Nullable
     private NetworkAddressService networkAddressService;
 
     @Activate
@@ -62,8 +66,8 @@ public class KNXHandlerFactory 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 (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) {
             ThingUID ipBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration);
             return super.createThing(thingTypeUID, configuration, ipBridgeUID, null);
@@ -79,7 +83,7 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
     }
 
     @Override
-    protected ThingHandler createHandler(Thing thing) {
+    protected @Nullable ThingHandler createHandler(Thing thing) {
         if (thing.getThingTypeUID().equals(THING_TYPE_IP_BRIDGE)) {
             return new IPBridgeThingHandler((Bridge) thing, networkAddressService);
         } else if (thing.getThingTypeUID().equals(THING_TYPE_SERIAL_BRIDGE)) {
@@ -90,7 +94,8 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
         return null;
     }
 
-    private ThingUID getIPBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) {
+    private ThingUID getIPBridgeThingUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
+            Configuration configuration) {
         if (thingUID != null) {
             return thingUID;
         }
@@ -98,7 +103,7 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
         return new ThingUID(thingTypeUID, ipAddress);
     }
 
-    private ThingUID getSerialBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID,
+    private ThingUID getSerialBridgeThingUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
             Configuration configuration) {
         if (thingUID != null) {
             return thingUID;
index c6fa8bdbb699952ae9da0ba5ea9f0fcb48f8467b..d7282a62ecc5b190b69088889d8fc662a88c334b 100644 (file)
@@ -53,9 +53,9 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
     private final Logger logger = LoggerFactory.getLogger(IPBridgeThingHandler.class);
 
     private @Nullable IPClient client = null;
-    private final NetworkAddressService networkAddressService;
+    private @Nullable final NetworkAddressService networkAddressService;
 
-    public IPBridgeThingHandler(Bridge bridge, NetworkAddressService networkAddressService) {
+    public IPBridgeThingHandler(Bridge bridge, @Nullable NetworkAddressService networkAddressService) {
         super(bridge);
         this.networkAddressService = networkAddressService;
     }
@@ -171,6 +171,11 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
         if (!config.getLocalIp().isEmpty()) {
             localEndPoint = new InetSocketAddress(config.getLocalIp(), 0);
         } else {
+            if (networkAddressService == null) {
+                logger.debug("NetworkAddressService not available, cannot create bridge {}", thing.getUID());
+                updateStatus(ThingStatus.OFFLINE);
+                return;
+            }
             localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0);
         }