]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hue] Catch exception of 'AllGroup' does not exist (#9502)
authorChristoph Weitkamp <github@christophweitkamp.de>
Fri, 25 Dec 2020 14:44:03 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Fri, 25 Dec 2020 14:44:03 +0000 (15:44 +0100)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java

index 463ed8cb70a48116e73caeef69d2b7d757f417b2..4a42c69e2620e4736d39648e9e57e6d23c4aeb1b 100644 (file)
@@ -12,6 +12,7 @@
  */
 package org.openhab.binding.hue.internal;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Type;
@@ -425,8 +426,6 @@ public class HueBridge {
      * @return all lights pseudo group
      */
     public Group getAllGroup() {
-        requireAuthentication();
-
         return new Group();
     }
 
@@ -448,14 +447,21 @@ public class HueBridge {
 
         if (groupMap.get("0") == null) {
             // Group 0 is not returned, we create it as in fact it exists
-            groupList.add(getGroup(new Group()));
+            try {
+                groupList.add(getGroup(getAllGroup()));
+            } catch (FileNotFoundException e) {
+                // We need a special exception handling here to further support deCONZ REST API. On deCONZ group "0" may
+                // not exist and the APIs will return a different HTTP status code if requesting a non existing group
+                // (Hue: 200, deCONZ: 404).
+                // see https://github.com/openhab/openhab-addons/issues/9175
+                logger.debug("Cannot find AllGroup with id \"0\" on Hue Bridge. Skipping it.");
+            }
         }
 
-        for (String id : groupMap.keySet()) {
-            FullGroup group = groupMap.get(id);
+        groupMap.forEach((id, group) -> {
             group.setId(id);
             groupList.add(group);
-        }
+        });
 
         return groupList;
     }
index b341d053522779c902f4f9456acb029f03358240..28e82e65611679233715c007acbd22915bbd9b7f 100644 (file)
@@ -140,7 +140,7 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
                 }
             } catch (ApiException | IOException e) {
                 if (hueBridge != null && lastBridgeConnectionState) {
-                    logger.debug("Connection to Hue Bridge {} lost.", hueBridge.getIPAddress());
+                    logger.debug("Connection to Hue Bridge {} lost: {}", hueBridge.getIPAddress(), e.getMessage(), e);
                     lastBridgeConnectionState = false;
                     onConnectionLost();
                 }