]> git.basschouten.com Git - openhab-addons.git/blob
fe23188d6b9b84094ab2a2572d063c95791b2850
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.knx.internal.profiles;
14
15 import static org.openhab.binding.knx.internal.KNXBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.thing.Channel;
20 import org.openhab.core.thing.profiles.ProfileAdvisor;
21 import org.openhab.core.thing.profiles.ProfileTypeUID;
22 import org.openhab.core.thing.profiles.SystemProfiles;
23 import org.openhab.core.thing.type.ChannelType;
24 import org.openhab.core.thing.type.ChannelTypeUID;
25 import org.osgi.service.component.annotations.Component;
26
27 /**
28  * Advisor, provider and factory for the specialized KNX profiles.
29  *
30  * @author Simon Kaufmann - initial contribution and API.
31  *
32  */
33 @Component
34 @NonNullByDefault
35 public class KNXProfileAdvisor implements ProfileAdvisor {
36
37     @Override
38     public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
39         ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
40         if (channelTypeUID == null || !channelTypeUID.getBindingId().equals(BINDING_ID)) {
41             return null;
42         }
43         return getSuggestedProfileTypeUID(channelTypeUID);
44     }
45
46     @Override
47     public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
48         return getSuggestedProfileTypeUID(channelType.getUID());
49     }
50
51     private ProfileTypeUID getSuggestedProfileTypeUID(ChannelTypeUID channelTypeUID) {
52         if (isControl(channelTypeUID)) {
53             return SystemProfiles.FOLLOW;
54         } else {
55             return SystemProfiles.DEFAULT;
56         }
57     }
58
59     public static boolean isControl(ChannelTypeUID channelTypeUID) {
60         return CONTROL_CHANNEL_TYPES.contains(channelTypeUID.getId());
61     }
62 }