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.leapmotion.internal;
15 import java.util.Collection;
16 import java.util.Locale;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.library.CoreItemFactory;
23 import org.openhab.core.thing.Channel;
24 import org.openhab.core.thing.profiles.Profile;
25 import org.openhab.core.thing.profiles.ProfileAdvisor;
26 import org.openhab.core.thing.profiles.ProfileCallback;
27 import org.openhab.core.thing.profiles.ProfileContext;
28 import org.openhab.core.thing.profiles.ProfileFactory;
29 import org.openhab.core.thing.profiles.ProfileType;
30 import org.openhab.core.thing.profiles.ProfileTypeBuilder;
31 import org.openhab.core.thing.profiles.ProfileTypeProvider;
32 import org.openhab.core.thing.profiles.ProfileTypeUID;
33 import org.openhab.core.thing.profiles.TriggerProfileType;
34 import org.openhab.core.thing.type.ChannelType;
35 import org.openhab.core.thing.type.ChannelTypeUID;
36 import org.osgi.service.component.annotations.Component;
39 * This class defines and provides all profiles and their types of this binding.
41 * @author Kai Kreuzer - Initial contribution
46 public class LeapMotionProfileFactory implements ProfileFactory, ProfileAdvisor, ProfileTypeProvider {
48 static final ProfileTypeUID UID_SWITCH = new ProfileTypeUID(LeapMotionBindingConstants.BINDING_ID, "switch");
49 static final ProfileTypeUID UID_DIMMER = new ProfileTypeUID(LeapMotionBindingConstants.BINDING_ID, "dimmer");
50 static final ProfileTypeUID UID_COLOR = new ProfileTypeUID(LeapMotionBindingConstants.BINDING_ID, "color");
52 private static final TriggerProfileType SWITCH_TYPE = ProfileTypeBuilder.newTrigger(UID_SWITCH, "Toggle Switch")
53 .withSupportedItemTypes(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER, CoreItemFactory.COLOR)
54 .withSupportedChannelTypeUIDs(LeapMotionBindingConstants.CHANNEL_GESTURE_UID).build();
56 private static final TriggerProfileType DIMMER_TYPE = ProfileTypeBuilder.newTrigger(UID_DIMMER, "Dimmer Control")
57 .withSupportedItemTypes(CoreItemFactory.DIMMER, CoreItemFactory.COLOR)
58 .withSupportedChannelTypeUIDs(LeapMotionBindingConstants.CHANNEL_GESTURE_UID).build();
60 private static final TriggerProfileType COLOR_TYPE = ProfileTypeBuilder.newTrigger(UID_COLOR, "Color Control")
61 .withSupportedItemTypes(CoreItemFactory.COLOR)
62 .withSupportedChannelTypeUIDs(LeapMotionBindingConstants.CHANNEL_GESTURE_UID).build();
65 public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
66 return Stream.of(UID_SWITCH, UID_DIMMER, UID_COLOR).collect(Collectors.toSet());
70 public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
71 return Stream.of(SWITCH_TYPE, DIMMER_TYPE, COLOR_TYPE).collect(Collectors.toSet());
75 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
76 return getSuggestedProfileTypeUID(channel.getChannelTypeUID(), itemType);
80 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
81 return getSuggestedProfileTypeUID(channelType.getUID(), itemType);
84 private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
85 @Nullable String itemType) {
86 if (LeapMotionBindingConstants.CHANNEL_GESTURE_UID.equals(channelTypeUID) && itemType != null) {
88 case CoreItemFactory.SWITCH:
90 case CoreItemFactory.DIMMER:
92 case CoreItemFactory.COLOR:
102 public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
103 ProfileContext profileContext) {
104 if (UID_SWITCH.equals(profileTypeUID)) {
105 return new LeapMotionSwitchProfile(callback);
106 } else if (UID_DIMMER.equals(profileTypeUID)) {
107 return new LeapMotionDimmerProfile(callback, profileContext);
108 } else if (UID_COLOR.equals(profileTypeUID)) {
109 return new LeapMotionColorProfile(callback);