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.enocean.internal.profiles;
15 import static org.openhab.binding.enocean.internal.profiles.EnOceanProfiles.*;
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;
26 * The {@link RockerSwitchActionToggleSwitchProfile} is used for channel rockerSwitchAction to be able to bind this
27 * trigger channel directly to a switch item
29 * @author Daniel Weber - Initial contribution
32 public class RockerSwitchActionToggleSwitchProfile extends RockerSwitchActionBaseProfile {
34 public RockerSwitchActionToggleSwitchProfile(ProfileCallback callback, ProfileContext context) {
35 super(callback, context);
39 public ProfileTypeUID getProfileTypeUID() {
40 return ROCKERSWITCHACTION_TOGGLE_SWITCH;
44 public void onStateUpdateFromItem(State state) {
45 previousState = state.as(OnOffType.class);
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;