]> git.basschouten.com Git - openhab-addons.git/commitdiff
[openweathermap] Bridge status set to ONLINE when no attached things (#11360)
authorlolodomo <lg.hc@free.fr>
Mon, 11 Oct 2021 11:15:46 +0000 (13:15 +0200)
committerGitHub <noreply@github.com>
Mon, 11 Oct 2021 11:15:46 +0000 (13:15 +0200)
Fix #11191

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAPIHandler.java

index 644065d1473fc268b3cb26ce52ccbb3e85c4e7be..042aa3c5ef81d974af62809c68640493480c7de2 100644 (file)
@@ -14,6 +14,7 @@ package org.openhab.binding.openweathermap.internal.handler;
 
 import static org.openhab.binding.openweathermap.internal.OpenWeatherMapBindingConstants.*;
 
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -151,21 +152,29 @@ public class OpenWeatherMapAPIHandler extends BaseBridgeHandler {
     }
 
     private void determineBridgeStatus() {
-        ThingStatus status = ThingStatus.OFFLINE;
-        for (Thing thing : getThing().getThings()) {
-            if (ThingStatus.ONLINE.equals(thing.getStatus())) {
-                status = ThingStatus.ONLINE;
-                break;
+        ThingStatus status = ThingStatus.ONLINE;
+        List<Thing> childs = getThing().getThings();
+        if (!childs.isEmpty()) {
+            status = ThingStatus.OFFLINE;
+            for (Thing thing : childs) {
+                if (ThingStatus.ONLINE.equals(thing.getStatus())) {
+                    status = ThingStatus.ONLINE;
+                    break;
+                }
             }
         }
         updateStatus(status);
     }
 
     private void updateThings() {
-        ThingStatus status = ThingStatus.OFFLINE;
-        for (Thing thing : getThing().getThings()) {
-            if (ThingStatus.ONLINE.equals(updateThing((AbstractOpenWeatherMapHandler) thing.getHandler(), thing))) {
-                status = ThingStatus.ONLINE;
+        ThingStatus status = ThingStatus.ONLINE;
+        List<Thing> childs = getThing().getThings();
+        if (!childs.isEmpty()) {
+            status = ThingStatus.OFFLINE;
+            for (Thing thing : childs) {
+                if (ThingStatus.ONLINE.equals(updateThing((AbstractOpenWeatherMapHandler) thing.getHandler(), thing))) {
+                    status = ThingStatus.ONLINE;
+                }
             }
         }
         updateStatus(status);