]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hpprinter] implement uuid as repr. prop. to stop discovery duplicates (#8810)
authorAndrew Fiddian-Green <software@whitebear.ch>
Thu, 22 Oct 2020 17:19:01 +0000 (18:19 +0100)
committerGitHub <noreply@github.com>
Thu, 22 Oct 2020 17:19:01 +0000 (19:19 +0200)
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterConfiguration.java
bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterDiscoveryParticipant.java
bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/api/HPProperties.java
bundles/org.openhab.binding.hpprinter/src/main/resources/OH-INF/thing/thing-printer.xml

index 8b05ce871cd7c0e37f653cd0382ff2f0c36c14c5..37666d493b50dd5d25f089430900a69e76cab879 100644 (file)
@@ -25,8 +25,10 @@ public class HPPrinterConfiguration {
     public static final String IP_ADDRESS = "ipAddress";
     public static final String USAGE_INTERVAL = "usageInterval";
     public static final String STATUS_INTERVAL = "statusInterval";
+    public static final String UUID = "uuid";
 
     public @Nullable String ipAddress;
     public int usageInterval;
     public int statusInterval;
+    public @Nullable String uuid;
 }
index 7d13afe28860a3a5a27310f2b36edca09e1e7ff3..2febf84dff9abcb3a66bb1035c14432fdd22897b 100644 (file)
@@ -71,8 +71,9 @@ public class HPPrinterDiscoveryParticipant implements MDNSDiscoveryParticipant {
                 String label = service.getName();
 
                 properties.put(HPPrinterConfiguration.IP_ADDRESS, inetAddress);
-                DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
-                        .build();
+                properties.put(HPPrinterConfiguration.UUID, service.getPropertyString("UUID"));
+                DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
+                        .withRepresentationProperty(HPPrinterConfiguration.UUID).withLabel(label).build();
                 logger.trace("Created a DiscoveryResult {} for printer on host '{}' name '{}'", result, inetAddress,
                         label);
                 return result;
index b3ebb62d71cc43a3e0ea8e2013366e63b6a8d71d..51d30c97a0c5c435d8a35290360be9c01ef7a3b8 100644 (file)
@@ -16,6 +16,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.hpprinter.internal.HPPrinterConfiguration;
 import org.openhab.core.thing.Thing;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -42,6 +43,8 @@ public class HPProperties {
                     element.getElementsByTagName("dd:SerialNumber").item(0).getTextContent());
             properties.put(Thing.PROPERTY_MODEL_ID,
                     element.getElementsByTagName("dd:ProductNumber").item(0).getTextContent());
+            properties.put(HPPrinterConfiguration.UUID,
+                    element.getElementsByTagName("dd:UUID").item(0).getTextContent());
             Node firmwareDate = element.getElementsByTagName("dd:Version").item(0);
             properties.put(Thing.PROPERTY_FIRMWARE_VERSION, firmwareDate.getChildNodes().item(0).getTextContent());
         }
index 3e0d077e3d3caba2bf0cdc616bc76e4c3347843c..9b385779198da6dfeaef551cc371d64b84310ef6 100644 (file)
@@ -19,8 +19,9 @@
                </channel-groups>
                <properties>
                        <property name="vendor">HP</property>
+                       <property name="uuid"></property>
                </properties>
-               <representation-property>serialNumber</representation-property>
+               <representation-property>uuid</representation-property>
                <config-description-ref uri="thing-type:hpprinter:config"/>
        </thing-type>