From 60b4dad600ef0c1181073f99b294318549570d0c Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 11 Oct 2021 13:15:46 +0200 Subject: [PATCH] [openweathermap] Bridge status set to ONLINE when no attached things (#11360) Fix #11191 Signed-off-by: Laurent Garnier --- .../handler/OpenWeatherMapAPIHandler.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAPIHandler.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAPIHandler.java index 644065d1473f..042aa3c5ef81 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAPIHandler.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapAPIHandler.java @@ -14,6 +14,7 @@ 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 void childHandlerDisposed(ThingHandler childHandler, Thing childThing) { } 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 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 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);