2 * Copyright (c) 2010-2023 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, KM200ChannelTypeProvider.class })
39 public class KM200ChannelTypeProvider implements ChannelTypeProvider, ChannelGroupTypeProvider {
40 private final List<ChannelType> channelTypes = new CopyOnWriteArrayList<>();
41 private final List<ChannelGroupType> channelGroupTypes = new CopyOnWriteArrayList<>();
44 public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
49 public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
50 for (ChannelType channelType : channelTypes) {
51 if (channelType.getUID().equals(channelTypeUID)) {
59 public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
60 return channelGroupTypes;
64 public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
65 @Nullable Locale locale) {
66 for (ChannelGroupType channelGroupType : channelGroupTypes) {
67 if (channelGroupType.getUID().equals(channelGroupTypeUID)) {
68 return channelGroupType;
74 public void addChannelType(ChannelType type) {
75 channelTypes.add(type);
78 public void removeChannelType(ChannelType type) {
79 channelTypes.remove(type);
82 public void removeChannelTypesForThing(ThingUID uid) {
83 List<ChannelType> removes = new ArrayList<>();
84 for (ChannelType c : channelTypes) {
85 if (c.getUID().getAsString().startsWith(uid.getAsString())) {
89 channelTypes.removeAll(removes);