2 * Copyright (c) 2010-2020 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.km200.internal;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 import java.util.Locale;
19 import java.util.concurrent.CopyOnWriteArrayList;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.thing.ThingUID;
24 import org.openhab.core.thing.type.ChannelGroupType;
25 import org.openhab.core.thing.type.ChannelGroupTypeProvider;
26 import org.openhab.core.thing.type.ChannelGroupTypeUID;
27 import org.openhab.core.thing.type.ChannelType;
28 import org.openhab.core.thing.type.ChannelTypeProvider;
29 import org.openhab.core.thing.type.ChannelTypeUID;
30 import org.osgi.service.component.annotations.Component;
33 * Extends the ChannelTypeProvider for user defined channel and channel group types.
35 * @author Markus Eckhardt - Initial contribution
37 @Component(service = { ChannelTypeProvider.class, ChannelGroupTypeProvider.class,
38 KM200ChannelTypeProvider.class }, immediate = true)
40 public class KM200ChannelTypeProvider implements ChannelTypeProvider, ChannelGroupTypeProvider {
41 private final List<ChannelType> channelTypes = new CopyOnWriteArrayList<>();
42 private final List<ChannelGroupType> channelGroupTypes = new CopyOnWriteArrayList<>();
45 public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
50 public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
51 for (ChannelType channelType : channelTypes) {
52 if (channelType.getUID().equals(channelTypeUID)) {
60 public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
61 return channelGroupTypes;
65 public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
66 @Nullable Locale locale) {
67 for (ChannelGroupType channelGroupType : channelGroupTypes) {
68 if (channelGroupType.getUID().equals(channelGroupTypeUID)) {
69 return channelGroupType;
75 public void addChannelType(ChannelType type) {
76 channelTypes.add(type);
79 public void removeChannelType(ChannelType type) {
80 channelTypes.remove(type);
83 public void removeChannelTypesForThing(ThingUID uid) {
84 List<ChannelType> removes = new ArrayList<>();
85 for (ChannelType c : channelTypes) {
86 if (c.getUID().getAsString().startsWith(uid.getAsString())) {
90 channelTypes.removeAll(removes);