]> git.basschouten.com Git - openhab-addons.git/blob
9604b5cf421787e45b0527b83ff20c4e17cd90cb
[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.PlayPauseType;
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 RockerSwitchActionTogglePlayerProfile} is used for channel rockerSwitchAction to be able to bind this
27  * trigger channel directly to a player item
28  * 
29  * @author Daniel Weber - Initial contribution
30  */
31 @NonNullByDefault
32 public class RockerSwitchActionTogglePlayerProfile extends RockerSwitchActionBaseProfile {
33
34     public RockerSwitchActionTogglePlayerProfile(ProfileCallback callback, ProfileContext context) {
35         super(callback, context);
36     }
37
38     @Override
39     public ProfileTypeUID getProfileTypeUID() {
40         return ROCKERSWITCHACTION_TOGGLE_PLAYER;
41     }
42
43     @Override
44     public void onStateUpdateFromItem(State state) {
45         previousState = state.as(PlayPauseType.class);
46     }
47
48     @Override
49     public void onTriggerFromHandler(String event) {
50         // Ignore released event
51         if (!CommonTriggerEvents.RELEASED.equals(event) && isEventValid(event)) {
52             PlayPauseType newState = PlayPauseType.PLAY.equals(previousState) ? PlayPauseType.PAUSE
53                     : PlayPauseType.PLAY;
54             callback.sendCommand(newState);
55             previousState = newState;
56         }
57     }
58 }