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.ChannelGroupType;
25 import org.openhab.core.thing.type.ChannelGroupTypeProvider;
26 import org.openhab.core.thing.type.ChannelGroupTypeUID;
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 ChannelGroupTypes from all Homematic bridges.
35 * @author Michael Reitler - Initial contribution
37 @Component(service = { HomematicChannelGroupTypeProvider.class, ChannelGroupTypeProvider.class })
38 public class HomematicChannelGroupTypeProviderImpl implements HomematicChannelGroupTypeProvider {
39 private final Map<ChannelGroupTypeUID, ChannelGroupType> channelGroupTypesByUID = new HashMap<>();
40 protected List<HomematicThingTypeExcluder> homematicThingTypeExcluders = new CopyOnWriteArrayList<>();
42 @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
43 protected void addHomematicThingTypeExcluder(HomematicThingTypeExcluder homematicThingTypeExcluder) {
44 if (homematicThingTypeExcluders != null) {
45 homematicThingTypeExcluders.add(homematicThingTypeExcluder);
49 protected void removeHomematicThingTypeExcluder(HomematicThingTypeExcluder homematicThingTypeExcluder) {
50 if (homematicThingTypeExcluders != null) {
51 homematicThingTypeExcluders.remove(homematicThingTypeExcluder);
55 private boolean isChannelGroupTypeExcluded(ChannelGroupTypeUID channelGroupTypeUID) {
56 // delegate to excluders
57 for (HomematicThingTypeExcluder excluder : homematicThingTypeExcluders) {
58 if (excluder.isChannelGroupTypeExcluded(channelGroupTypeUID)) {
66 public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
67 return isChannelGroupTypeExcluded(channelGroupTypeUID) ? null : channelGroupTypesByUID.get(channelGroupTypeUID);
71 public ChannelGroupType getInternalChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID) {
72 return channelGroupTypesByUID.get(channelGroupTypeUID);
76 public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
77 Collection<ChannelGroupType> result = new ArrayList<>();
78 for (ChannelGroupTypeUID uid : channelGroupTypesByUID.keySet()) {
79 if (!isChannelGroupTypeExcluded(uid)) {
80 result.add(channelGroupTypesByUID.get(uid));
87 public void addChannelGroupType(ChannelGroupType channelGroupType) {
88 channelGroupTypesByUID.put(channelGroupType.getUID(), channelGroupType);