]> git.basschouten.com Git - openhab-addons.git/blob
988683975d3b768de3643a6477006f51d50b23d4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.nibeuplink.internal.handler;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.openhab.core.thing.Channel;
21 import org.openhab.core.thing.ChannelGroupUID;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24
25 /**
26  * generic implementation of handler logic
27  *
28  * @author Alexander Friese - initial contribution
29  */
30 @NonNullByDefault
31 public class GenericHandler extends UplinkBaseHandler {
32
33     /**
34      * constructor, called by the factory
35      *
36      * @param thing instance of the thing, passed in by the factory
37      * @param httpClient the httpclient that communicates with the API
38      */
39     public GenericHandler(Thing thing, HttpClient httpClient) {
40         super(thing, httpClient);
41     }
42
43     @Override
44     public @Nullable Channel getSpecificChannel(String channelId) {
45         Channel channel = getThing().getChannel(channelId);
46         if (channel == null) {
47             for (ChannelGroupUID channelGroupUID : getRegisteredGroups()) {
48                 channel = getThing().getChannel(new ChannelUID(channelGroupUID, channelId));
49                 if (channel != null) {
50                     break;
51                 }
52             }
53         }
54         return channel;
55     }
56
57     @Override
58     public List<Channel> getChannels() {
59         return getThing().getChannels();
60     }
61 }