]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hue] Make sure the serial number will be in lowercase (#9367)
authorlolodomo <lg.hc@free.fr>
Thu, 24 Dec 2020 01:22:54 +0000 (02:22 +0100)
committerGitHub <noreply@github.com>
Thu, 24 Dec 2020 01:22:54 +0000 (17:22 -0800)
* [hue] Make sure the serial number will be in lowercase

Necessary for the auto-ignore discovery feature with the representation property.

Fix #9364

* Check that the serial number is not null
* Check that the serial number is not blank
* Build a discovery result even without a serial number

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeDiscoveryParticipant.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/discovery/HueBridgeNupnpDiscovery.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java

index 1c47be34b60fb3899cc96044ebe509bdb3d62521..ebdc19245fbb14b54abf81b3eefaaeeae8538a4b 100644 (file)
@@ -57,11 +57,18 @@ public class HueBridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
             properties.put(HOST, device.getDetails().getBaseURL().getHost());
             properties.put(PORT, device.getDetails().getBaseURL().getPort());
             properties.put(PROTOCOL, device.getDetails().getBaseURL().getProtocol());
-            properties.put(PROPERTY_SERIAL_NUMBER, device.getDetails().getSerialNumber());
+            String serialNumber = device.getDetails().getSerialNumber();
+            DiscoveryResult result;
+            if (serialNumber != null && !serialNumber.isBlank()) {
+                properties.put(PROPERTY_SERIAL_NUMBER, serialNumber.toLowerCase());
 
-            DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
-                    .withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(PROPERTY_SERIAL_NUMBER)
-                    .build();
+                result = DiscoveryResultBuilder.create(uid).withProperties(properties)
+                        .withLabel(device.getDetails().getFriendlyName())
+                        .withRepresentationProperty(PROPERTY_SERIAL_NUMBER).build();
+            } else {
+                result = DiscoveryResultBuilder.create(uid).withProperties(properties)
+                        .withLabel(device.getDetails().getFriendlyName()).build();
+            }
             return result;
         } else {
             return null;
@@ -73,11 +80,12 @@ public class HueBridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
         DeviceDetails details = device.getDetails();
         if (details != null) {
             ModelDetails modelDetails = details.getModelDetails();
-            if (modelDetails != null) {
+            String serialNumber = details.getSerialNumber();
+            if (modelDetails != null && serialNumber != null && !serialNumber.isBlank()) {
                 String modelName = modelDetails.getModelName();
                 if (modelName != null) {
                     if (modelName.startsWith("Philips hue bridge")) {
-                        return new ThingUID(THING_TYPE_BRIDGE, details.getSerialNumber());
+                        return new ThingUID(THING_TYPE_BRIDGE, serialNumber.toLowerCase());
                     }
                 }
             }
index 9e19852481f0168c167de6f43be56f60cf74ee4b..b071ce87ef354475aa53c496c3a3afa0cddd1660 100644 (file)
@@ -16,7 +16,13 @@ import static org.openhab.binding.hue.internal.HueBindingConstants.*;
 import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
 
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -82,6 +88,7 @@ public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService {
             if (isReachableAndValidHueBridge(bridge)) {
                 String host = bridge.getInternalIpAddress();
                 String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10);
+                serialNumber = serialNumber.toLowerCase();
                 ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
                 DiscoveryResult result = DiscoveryResultBuilder.create(uid)
                         .withProperties(buildProperties(host, serialNumber))
index 00d5dce23169b2bdd32347137fa9f5a1db33e0d9..b341d053522779c902f4f9456acb029f03358240 100644 (file)
@@ -734,6 +734,7 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
             if (config != null) {
                 Map<String, String> properties = editProperties();
                 String serialNumber = config.getBridgeId().substring(0, 6) + config.getBridgeId().substring(10);
+                serialNumber = serialNumber.toLowerCase();
                 properties.put(PROPERTY_SERIAL_NUMBER, serialNumber);
                 properties.put(PROPERTY_MODEL_ID, config.getModelId());
                 properties.put(PROPERTY_MAC_ADDRESS, config.getMACAddress());