]> git.basschouten.com Git - openhab-addons.git/blob
124255021577c71aa3f4520dc144a7533761f1b4
[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.enocean.internal.profiles;
14
15 import static org.openhab.binding.enocean.internal.profiles.EnOceanProfiles.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.thing.CommonTriggerEvents;
20 import org.openhab.core.thing.profiles.ProfileCallback;
21 import org.openhab.core.thing.profiles.ProfileContext;
22 import org.openhab.core.thing.profiles.ProfileTypeUID;
23 import org.openhab.core.types.State;
24
25 /**
26  * The {@link RockerSwitchActionToggleSwitchProfile} is used for channel rockerSwitchAction to be able to bind this
27  * trigger channel directly to a switch item
28  * 
29  * @author Daniel Weber - Initial contribution
30  */
31 @NonNullByDefault
32 public class RockerSwitchActionToggleSwitchProfile extends RockerSwitchActionBaseProfile {
33
34     public RockerSwitchActionToggleSwitchProfile(ProfileCallback callback, ProfileContext context) {
35         super(callback, context);
36     }
37
38     @Override
39     public ProfileTypeUID getProfileTypeUID() {
40         return ROCKERSWITCHACTION_TOGGLE_SWITCH;
41     }
42
43     @Override
44     public void onStateUpdateFromItem(State state) {
45         previousState = state.as(OnOffType.class);
46     }
47
48     @Override
49     public void onTriggerFromHandler(String event) {
50         // Ignore released event
51         if (!CommonTriggerEvents.RELEASED.equals(event) && isEventValid(event)) {
52             OnOffType newState = OnOffType.ON.equals(previousState) ? OnOffType.OFF : OnOffType.ON;
53             callback.sendCommand(newState);
54             previousState = newState;
55         }
56     }
57 }