]> git.basschouten.com Git - openhab-addons.git/blob
2dd2c639f14c96e5317bc550416c8533f19149dd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.velux.internal.handler;
14
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.velux.internal.handler.utils.ExtendedBaseBridgeHandler;
20 import org.openhab.core.thing.Channel;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /***
27  * The class {@link BridgeChannels} provides methods for dealing with
28  * properties.
29  * <ul>
30  * <li>{@link #getAllChannelUIDs}</LI>
31  * <li>{@link #getAllLinkedChannelUIDs}</LI>
32  * </UL>
33  * <P>
34  * Noninstantiable utility class
35  * </P>
36  *
37  * @author Guenther Schreiner - Initial contribution
38  */
39 @NonNullByDefault
40 final class BridgeChannels {
41     private static final Logger LOGGER = LoggerFactory.getLogger(BridgeChannels.class);
42
43     /*
44      * ************************
45      * ***** Constructors *****
46      */
47
48     // Suppress default constructor for non-instantiability
49
50     private BridgeChannels() {
51         throw new AssertionError();
52     }
53
54     /*
55      * **************************
56      * ***** Public Methods *****
57      */
58
59     /**
60      * Return the Channel identifiers of all child things and the bridge things.
61      * <p>
62      *
63      * @param bridge which will be scrutinized for things.
64      * @return <b>channelUIDs</B> of type {@link Set} of {@link ChannelUID}s.
65      */
66     static Set<ChannelUID> getAllChannelUIDs(ExtendedBaseBridgeHandler bridge) {
67         Set<ChannelUID> channelUIDs = new HashSet<>();
68         Set<Thing> things = new HashSet<>(bridge.getThing().getThings());
69         things.add(bridge.getThing());
70         for (Thing thing : things) {
71             for (Channel channel : thing.getChannels()) {
72                 channelUIDs.add(channel.getUID());
73             }
74         }
75         LOGGER.trace("getAllChannelUIDs() returns {}.", channelUIDs);
76         return channelUIDs;
77     }
78
79     /**
80      * Return the Channel identifiers of all child things and the bridge things,
81      * which are linked.
82      * <p>
83      *
84      * @param bridge which will be scrutinized for things.
85      * @return <b>channelUIDs</B> of type {@link Set} of {@link ChannelUID}s.
86      */
87     static Set<ChannelUID> getAllLinkedChannelUIDs(ExtendedBaseBridgeHandler bridge) {
88         Set<ChannelUID> channelUIDs = new HashSet<>();
89         Set<Thing> things = new HashSet<>(bridge.getThing().getThings());
90         things.add(bridge.getThing());
91         for (Thing thing : things) {
92             for (Channel channel : thing.getChannels()) {
93                 if (bridge.isLinked(channel.getUID())) {
94                     channelUIDs.add(channel.getUID());
95                 }
96             }
97         }
98         LOGGER.trace("getAllLinkedChannelUIDs() returns {}.", channelUIDs);
99         return channelUIDs;
100     }
101 }