From e439ad68f652b3b84d17feadf989f50f4e3816ab Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Thu, 22 Oct 2020 18:19:01 +0100 Subject: [PATCH] [hpprinter] implement uuid as repr. prop. to stop discovery duplicates (#8810) Signed-off-by: Andrew Fiddian-Green --- .../binding/hpprinter/internal/HPPrinterConfiguration.java | 2 ++ .../hpprinter/internal/HPPrinterDiscoveryParticipant.java | 5 +++-- .../openhab/binding/hpprinter/internal/api/HPProperties.java | 3 +++ .../src/main/resources/OH-INF/thing/thing-printer.xml | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterConfiguration.java b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterConfiguration.java index 8b05ce871cd..37666d493b5 100644 --- a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterConfiguration.java +++ b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterConfiguration.java @@ -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; } diff --git a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterDiscoveryParticipant.java b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterDiscoveryParticipant.java index 7d13afe2886..2febf84dff9 100644 --- a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/HPPrinterDiscoveryParticipant.java @@ -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; diff --git a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/api/HPProperties.java b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/api/HPProperties.java index b3ebb62d71c..51d30c97a0c 100644 --- a/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/api/HPProperties.java +++ b/bundles/org.openhab.binding.hpprinter/src/main/java/org/openhab/binding/hpprinter/internal/api/HPProperties.java @@ -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()); } diff --git a/bundles/org.openhab.binding.hpprinter/src/main/resources/OH-INF/thing/thing-printer.xml b/bundles/org.openhab.binding.hpprinter/src/main/resources/OH-INF/thing/thing-printer.xml index 3e0d077e3d3..9b385779198 100644 --- a/bundles/org.openhab.binding.hpprinter/src/main/resources/OH-INF/thing/thing-printer.xml +++ b/bundles/org.openhab.binding.hpprinter/src/main/resources/OH-INF/thing/thing-printer.xml @@ -19,8 +19,9 @@ HP + - serialNumber + uuid