]> git.basschouten.com Git - openhab-addons.git/blob
b247a43df647151417ad7f0baa4761b445850b33
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.leapmotion.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.thing.profiles.ProfileCallback;
18 import org.openhab.core.thing.profiles.ProfileTypeUID;
19 import org.openhab.core.thing.profiles.TriggerProfile;
20 import org.openhab.core.types.State;
21
22 /**
23  * The {@link LeapMotionSwitchProfile} class implements the behavior when being linked to a Switch item.
24  *
25  * @author Kai Kreuzer - Initial contribution
26  */
27 @NonNullByDefault
28 public class LeapMotionSwitchProfile implements TriggerProfile {
29
30     private ProfileCallback callback;
31     private boolean lastState = false;
32
33     public LeapMotionSwitchProfile(ProfileCallback callback) {
34         this.callback = callback;
35     }
36
37     @Override
38     public ProfileTypeUID getProfileTypeUID() {
39         return LeapMotionProfileFactory.UID_SWITCH;
40     }
41
42     @Override
43     public void onStateUpdateFromItem(State state) {
44         lastState = OnOffType.ON.equals(state.as(OnOffType.class));
45     }
46
47     @Override
48     public void onTriggerFromHandler(String event) {
49         if (event.equals(LeapMotionBindingConstants.GESTURE_TAP)) {
50             callback.sendCommand(OnOffType.from(!lastState));
51         }
52     }
53 }