]> git.basschouten.com Git - openhab-addons.git/blob
7fe87fe6b4deb1b469d616ad7e9f0b669e9dad65
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.remoteopenhab.internal;
14
15 import java.util.Collection;
16 import java.util.List;
17 import java.util.Locale;
18 import java.util.concurrent.CopyOnWriteArrayList;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.thing.type.ChannelType;
23 import org.openhab.core.thing.type.ChannelTypeProvider;
24 import org.openhab.core.thing.type.ChannelTypeUID;
25 import org.osgi.service.component.annotations.Component;
26
27 /**
28  * Channel type provider used for all the channel types built by the binding when building dynamically the channels.
29  * One different channel type is built for each different item type found on the remote openHAB server.
30  *
31  * @author Laurent Garnier - Initial contribution
32  */
33 @Component(service = { ChannelTypeProvider.class, RemoteopenhabChannelTypeProvider.class })
34 @NonNullByDefault
35 public class RemoteopenhabChannelTypeProvider implements ChannelTypeProvider {
36     private final List<ChannelType> channelTypes = new CopyOnWriteArrayList<>();
37
38     @Override
39     public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
40         return channelTypes;
41     }
42
43     @Override
44     public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
45         for (ChannelType channelType : channelTypes) {
46             if (channelType.getUID().equals(channelTypeUID)) {
47                 return channelType;
48             }
49         }
50         return null;
51     }
52
53     public void addChannelType(ChannelType type) {
54         channelTypes.add(type);
55     }
56
57     public void removeChannelType(ChannelType type) {
58         channelTypes.remove(type);
59     }
60 }