]> git.basschouten.com Git - openhab-addons.git/commitdiff
[amazonechocontrol] fix smarthome device naming (#10084)
authorJ-N-K <J-N-K@users.noreply.github.com>
Sun, 7 Feb 2021 21:56:31 +0000 (22:56 +0100)
committerGitHub <noreply@github.com>
Sun, 7 Feb 2021 21:56:31 +0000 (13:56 -0800)
* fix smarthome device naming
* toString

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java
bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/jsons/JsonSmartHomeCapabilities.java

index d69a041a56bae63422768242eb70549c82cf7c59..8615ef193db9baaa11e0c1ebc2f42bf202ba993e 100644 (file)
@@ -14,14 +14,10 @@ package org.openhab.binding.amazonechocontrol.internal.discovery;
 
 import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.*;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -180,7 +176,17 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
                 List<JsonSmartHomeDeviceAlias> aliases = shd.aliases;
                 if ("Amazon".equals(shd.manufacturerName) && driverIdentity != null
                         && "SonarCloudService".equals(driverIdentity.identifier)) {
-                    deviceName = "Alexa Guard on " + shd.friendlyName;
+                    List<@Nullable String> interfaces = shd.getCapabilities().stream().map(c -> c.interfaceName)
+                            .collect(Collectors.toList());
+                    if (interfaces.contains("Alexa.AcousticEventSensor")) {
+                        deviceName = "Alexa Guard on " + shd.friendlyName;
+                    } else if (interfaces.contains("Alexa.ColorController")) {
+                        deviceName = "Alexa Color Controller on " + shd.friendlyName;
+                    } else if (interfaces.contains("Alexa.PowerController")) {
+                        deviceName = "Alexa Plug on " + shd.friendlyName;
+                    } else {
+                        deviceName = "Unknown Device on " + shd.friendlyName;
+                    }
                 } else if ("Amazon".equals(shd.manufacturerName) && driverIdentity != null
                         && "OnGuardSmartHomeBridgeService".equals(driverIdentity.identifier)) {
                     deviceName = "Alexa Guard";
index baaafeb26db6db5b8cd2a080e46b9aa045d12b1b..fd8d21399e7392e9069aee4ccac75c566ae395b8 100644 (file)
@@ -29,15 +29,32 @@ public class JsonSmartHomeCapabilities {
         public @Nullable String version;
         public @Nullable String interfaceName;
         public @Nullable Properties properties;
+
+        @Override
+        public String toString() {
+            return "SmartHomeCapability{" + "capabilityType='" + capabilityType + '\'' + ", type='" + type + '\''
+                    + ", version='" + version + '\'' + ", interfaceName='" + interfaceName + '\'' + ", properties="
+                    + properties + '}';
+        }
     }
 
     public static class Properties {
         public @Nullable List<Property> supported;
+
+        @Override
+        public String toString() {
+            return "Properties{" + "supported=" + supported + '}';
+        }
     }
 
     public static class Property {
         public @Nullable String name;
     }
 
+    @Override
+    public String toString() {
+        return "JsonSmartHomeCapabilities{" + "capabilites=" + capabilites + '}';
+    }
+
     public @Nullable List<SmartHomeCapability> capabilites;
 }