Enhance getActiveChildren() (#16573)

Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Gaël L'hopital 2024-03-25 09:19:32 +01:00 committed by Ciprian Pascu
parent b861c02386
commit 8e4a8314e2

View File

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