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.homematic.internal.type;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Locale;
21 import java.util.concurrent.CopyOnWriteArrayList;
23 import org.openhab.binding.homematic.type.HomematicThingTypeExcluder;
24 import org.openhab.core.thing.type.ChannelType;
25 import org.openhab.core.thing.type.ChannelTypeProvider;
26 import org.openhab.core.thing.type.ChannelTypeUID;
27 import org.osgi.service.component.annotations.Component;
28 import org.osgi.service.component.annotations.Reference;
29 import org.osgi.service.component.annotations.ReferenceCardinality;
30 import org.osgi.service.component.annotations.ReferencePolicy;
33 * Provides all ChannelTypes from all Homematic bridges.
35 * @author Gerhard Riegler - Initial contribution
36 * @author Michael Reitler - Added HomematicThingTypeExcluder
38 @Component(service = { HomematicChannelTypeProvider.class, ChannelTypeProvider.class })
39 public class HomematicChannelTypeProviderImpl implements HomematicChannelTypeProvider {
40 private final Map<ChannelTypeUID, ChannelType> channelTypesByUID = new HashMap<>();
41 protected List<HomematicThingTypeExcluder> homematicThingTypeExcluders = new CopyOnWriteArrayList<>();
43 @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
44 protected void addHomematicThingTypeExcluder(HomematicThingTypeExcluder homematicThingTypeExcluder) {
45 if (homematicThingTypeExcluders != null) {
46 homematicThingTypeExcluders.add(homematicThingTypeExcluder);
50 protected void removeHomematicThingTypeExcluder(HomematicThingTypeExcluder homematicThingTypeExcluder) {
51 if (homematicThingTypeExcluders != null) {
52 homematicThingTypeExcluders.remove(homematicThingTypeExcluder);
56 private boolean isChannelTypeExcluded(ChannelTypeUID channelTypeUID) {
57 // delegate to excluders
58 for (HomematicThingTypeExcluder excluder : homematicThingTypeExcluders) {
59 if (excluder.isChannelTypeExcluded(channelTypeUID)) {
67 public Collection<ChannelType> getChannelTypes(Locale locale) {
68 Collection<ChannelType> result = new ArrayList<>();
69 for (ChannelTypeUID uid : channelTypesByUID.keySet()) {
70 if (!isChannelTypeExcluded(uid)) {
71 result.add(channelTypesByUID.get(uid));
78 public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
79 return isChannelTypeExcluded(channelTypeUID) ? null : channelTypesByUID.get(channelTypeUID);
83 public ChannelType getInternalChannelType(ChannelTypeUID channelTypeUID) {
84 return channelTypesByUID.get(channelTypeUID);
88 public void addChannelType(ChannelType channelType) {
89 channelTypesByUID.put(channelType.getUID(), channelType);