From e8ba8ec47bce0670cf7819de7a499a578dd56382 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Tue, 26 Jan 2021 09:20:39 -0700 Subject: [PATCH] [OmniLink] Use for each loop in getChildThing() (#9963) * Use for each loop in getChildThing() Signed-off-by: Ethan Dye * Further refine getChildThing() using stream map Signed-off-by: Ethan Dye * Fix spotless errors Signed-off-by: Ethan Dye --- .../internal/OmnilinkBindingConstants.java | 2 ++ .../handler/OmnilinkBridgeHandler.java | 20 ++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java index 05843027dbc..0baf6eac70c 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java @@ -185,4 +185,6 @@ public class OmnilinkBindingConstants { THING_TYPE_BUTTON, THING_TYPE_UNIT_UPB, THING_TYPE_THERMOSTAT, THING_TYPE_CONSOLE, THING_TYPE_AUDIO_ZONE, THING_TYPE_AUDIO_SOURCE, THING_TYPE_TEMP_SENSOR, THING_TYPE_HUMIDITY_SENSOR, THING_TYPE_LOCK, THING_TYPE_OUTPUT, THING_TYPE_UNIT, THING_TYPE_DIMMABLE); + public static final Set SUPPORTED_UNIT_TYPES_UIDS = Set.of(THING_TYPE_UNIT_UPB, THING_TYPE_ROOM, + THING_TYPE_FLAG, THING_TYPE_OUTPUT, THING_TYPE_DIMMABLE, THING_TYPE_UNIT); } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java index 7cc1056688d..52232bab26e 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java @@ -568,24 +568,8 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica } private Optional getUnitThing(int unitId) { - Optional theThing = getChildThing(THING_TYPE_UNIT_UPB, unitId); - if (!(theThing.isPresent())) { - theThing = getChildThing(THING_TYPE_ROOM, unitId); - } - if (!(theThing.isPresent())) { - theThing = getChildThing(THING_TYPE_FLAG, unitId); - } - if (!(theThing.isPresent())) { - theThing = getChildThing(THING_TYPE_OUTPUT, unitId); - } - if (!(theThing.isPresent())) { - theThing = getChildThing(THING_TYPE_DIMMABLE, unitId); - } - if (!(theThing.isPresent())) { - theThing = getChildThing(THING_TYPE_UNIT, unitId); - } - - return theThing; + return SUPPORTED_UNIT_TYPES_UIDS.stream().map(uid -> getChildThing(uid, unitId)).flatMap(Optional::stream) + .findFirst(); } public Optional getAudioPlayer() {