2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.remoteopenhab.internal;
15 import java.util.Collection;
16 import java.util.List;
17 import java.util.Locale;
18 import java.util.concurrent.CopyOnWriteArrayList;
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;
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.
31 * @author Laurent Garnier - Initial contribution
33 @Component(service = { ChannelTypeProvider.class, RemoteopenhabChannelTypeProvider.class })
35 public class RemoteopenhabChannelTypeProvider implements ChannelTypeProvider {
36 private final List<ChannelType> channelTypes = new CopyOnWriteArrayList<>();
39 public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
44 public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
45 for (ChannelType channelType : channelTypes) {
46 if (channelType.getUID().equals(channelTypeUID)) {
53 public void addChannelType(ChannelType type) {
54 channelTypes.add(type);
57 public void removeChannelType(ChannelType type) {
58 channelTypes.remove(type);