From 9dd2827148125e77a7b7aaf7f29f93547effb703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Mon, 25 Mar 2024 09:19:32 +0100 Subject: [PATCH] Enhance getActiveChildren() (#16573) Signed-off-by: clinique --- .../internal/handler/CommonInterface.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/CommonInterface.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/CommonInterface.java index 59e43d3016d..da571ce7a85 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/CommonInterface.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/CommonInterface.java @@ -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 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 getActiveChildren(FeatureArea area) { @@ -207,7 +205,7 @@ public interface CommonInterface { } default void proceedWithUpdate() { - updateReadings().forEach(dataSet -> setNewData(dataSet)); + updateReadings().forEach(this::setNewData); } default List updateReadings() { @@ -244,7 +242,6 @@ public interface CommonInterface { } default void removeChannels(List channels) { - ThingBuilder builder = editThing().withoutChannels(channels); - updateThing(builder.build()); + updateThing(editThing().withoutChannels(channels).build()); } }