]> git.basschouten.com Git - openhab-addons.git/commitdiff
Enhance getActiveChildren() (#16573)
authorGaël L'hopital <gael@lhopital.org>
Mon, 25 Mar 2024 08:19:32 +0000 (09:19 +0100)
committerGitHub <noreply@github.com>
Mon, 25 Mar 2024 08:19:32 +0000 (09:19 +0100)
Signed-off-by: clinique <gael@lhopital.org>
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/CommonInterface.java

index 59e43d3016d13cdcc3a859fc49a5a788e67a7208..da571ce7a857257c98ee82c75f5bdc4ad8a26c8d 100644 (file)
@@ -14,7 +14,6 @@ package org.openhab.binding.netatmo.internal.handler;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.stream.Stream;
@@ -107,7 +106,7 @@ public interface CommonInterface {
     }
 
     default void expireData() {
-        getCapabilities().values().forEach(cap -> cap.expireData());
+        getCapabilities().values().forEach(Capability::expireData);
     }
 
     default String getId() {
@@ -152,13 +151,12 @@ public interface CommonInterface {
     }
 
     default List<CommonInterface> getActiveChildren() {
-        Thing thing = getThing();
-        if (thing instanceof Bridge bridge) {
-            return bridge.getThings().stream().filter(Thing::isEnabled)
-                    .filter(th -> th.getStatusInfo().getStatusDetail() != ThingStatusDetail.BRIDGE_OFFLINE)
-                    .map(Thing::getHandler).filter(Objects::nonNull).map(CommonInterface.class::cast).toList();
-        }
-        return List.of();
+        return getThing() instanceof Bridge bridge
+                ? bridge.getThings().stream().filter(Thing::isEnabled)
+                        .filter(th -> th.getStatusInfo().getStatusDetail() != ThingStatusDetail.BRIDGE_OFFLINE)
+                        .map(Thing::getHandler).filter(CommonInterface.class::isInstance)
+                        .map(CommonInterface.class::cast).toList()
+                : List.of();
     }
 
     default Stream<CommonInterface> getActiveChildren(FeatureArea area) {
@@ -207,7 +205,7 @@ public interface CommonInterface {
     }
 
     default void proceedWithUpdate() {
-        updateReadings().forEach(dataSet -> setNewData(dataSet));
+        updateReadings().forEach(this::setNewData);
     }
 
     default List<NAObject> updateReadings() {
@@ -244,7 +242,6 @@ public interface CommonInterface {
     }
 
     default void removeChannels(List<Channel> channels) {
-        ThingBuilder builder = editThing().withoutChannels(channels);
-        updateThing(builder.build());
+        updateThing(editThing().withoutChannels(channels).build());
     }
 }