]> git.basschouten.com Git - openhab-addons.git/commitdiff
[km200] Fixed representation-property for discovery result (#9042)
authorChristoph Weitkamp <github@christophweitkamp.de>
Mon, 16 Nov 2020 20:34:35 +0000 (21:34 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Nov 2020 20:34:35 +0000 (12:34 -0800)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/discovery/KM200GatewayDiscoveryParticipant.java
bundles/org.openhab.binding.km200/src/main/resources/OH-INF/thing/device.xml

index f7c45b6956da0d571aac88fd5d5c822d842262bc..f2b6a4a94c67dee5e2ca46b4070f7f27f3dd31b3 100644 (file)
@@ -41,9 +41,10 @@ import org.slf4j.LoggerFactory;
 @Component(configurationPid = "binding.km200")
 public class KM200GatewayDiscoveryParticipant implements MDNSDiscoveryParticipant {
 
-    private final Logger logger = LoggerFactory.getLogger(KM200GatewayDiscoveryParticipant.class);
+    private static final Set<ThingTypeUID> SUPPORTED_ALL_THING_TYPES_UIDS = KM200GatewayHandler.SUPPORTED_THING_TYPES_UIDS;
+    private static final String IP4_ADDRESS = "ip4Address";
 
-    public static final Set<ThingTypeUID> SUPPORTED_ALL_THING_TYPES_UIDS = KM200GatewayHandler.SUPPORTED_THING_TYPES_UIDS;
+    private final Logger logger = LoggerFactory.getLogger(KM200GatewayDiscoveryParticipant.class);
 
     @Override
     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
@@ -52,17 +53,14 @@ public class KM200GatewayDiscoveryParticipant implements MDNSDiscoveryParticipan
 
     @Override
     public @Nullable DiscoveryResult createResult(ServiceInfo info) {
-        DiscoveryResult discoveryResult = null;
         ThingUID uid = getThingUID(info);
         logger.debug("MDNS info: {}, uid: {}", info, uid);
         if (uid != null) {
             InetAddress[] addrs = info.getInetAddresses();
             logger.debug("ip: {} id:{}", addrs[0].getHostAddress(), uid.getId());
-            discoveryResult = DiscoveryResultBuilder.create(uid).withProperty("ip4Address", addrs[0].getHostAddress())
-                    .withProperty("deviceId", uid.getId()).withRepresentationProperty(addrs[0].getHostAddress())
+            return DiscoveryResultBuilder.create(uid).withProperty(IP4_ADDRESS, addrs[0].getHostAddress())
+                    .withProperty("deviceId", uid.getId()).withRepresentationProperty(IP4_ADDRESS)
                     .withLabel("KM50/100/200 Gateway (" + addrs[0].getHostAddress() + ")").build();
-
-            return discoveryResult;
         }
         return null;
     }
@@ -83,8 +81,7 @@ public class KM200GatewayDiscoveryParticipant implements MDNSDiscoveryParticipan
                             Random rnd = new Random();
                             devId = String.valueOf(rnd.nextLong());
                         }
-                        ThingUID thinguid = new ThingUID(typeUID, devId);
-                        return thinguid;
+                        return new ThingUID(typeUID, devId);
                     } else {
                         logger.debug("No uuid property found");
                     }
@@ -102,8 +99,7 @@ public class KM200GatewayDiscoveryParticipant implements MDNSDiscoveryParticipan
     private @Nullable ThingTypeUID getThingTypeUID(ServiceInfo info) {
         InetAddress[] addrs = info.getInetAddresses();
         if (addrs.length > 0) {
-            String hardwareID;
-            hardwareID = info.getPropertyString("hwversion");
+            String hardwareID = info.getPropertyString("hwversion");
             logger.debug("hardwareID: {}", hardwareID);
             if (hardwareID != null && hardwareID.contains("iCom_Low")) {
                 return THING_TYPE_KMDEVICE;
index d0bfab44f4e993e8aa4309b4b7ccd52e61d4e521..81a8a08e43c7dca0048c5b2bf8c3b6b857db1955 100644 (file)
@@ -9,6 +9,8 @@
                <description>The KM200 binding is communicating with a Buderus Logamatic web KM200 / KM100 / KM50. It is possible to
                        receive and send parameters like string or float values.</description>
 
+               <representation-property>ip4Address</representation-property>
+
                <config-description>
                        <parameter name="ip4Address" type="text" required="true">
                                <label>IP4 Address</label>