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.eep.F6_02;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.Channel;
20 import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig;
21 import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.thing.CommonTriggerEvents;
26 import org.openhab.core.types.Command;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
32 * @author Daniel Weber - Initial contribution
34 public class F6_02_02 extends F6_02 {
40 public F6_02_02(ERP1Message packet) {
45 protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
46 Configuration config) {
49 if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
50 return getRockerSwitchAction(config);
52 byte dir1 = channelId.equals(CHANNEL_ROCKERSWITCH_CHANNELA) ? AI : BI;
53 byte dir2 = channelId.equals(CHANNEL_ROCKERSWITCH_CHANNELA) ? A0 : B0;
54 return getChannelEvent(dir1, dir2);
56 } else if (t21 && !nu) {
57 if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
58 return CommonTriggerEvents.RELEASED;
60 if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
61 return CommonTriggerEvents.DIR1_RELEASED;
62 } else if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
63 return CommonTriggerEvents.DIR2_RELEASED;
72 protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
73 Function<String, State> getCurrentStateFunc, Configuration config) {
74 if (command instanceof StringType) {
75 String s = ((StringType) command).toString();
77 if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) {
78 setStatus(_RPSMessage.T21Flag);
83 byte dir1 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? BI : AI;
84 byte dir2 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? B0 : A0;
86 if (s.equals(CommonTriggerEvents.DIR1_PRESSED)) {
87 setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
88 setData((byte) ((dir1 << 5) | PRESSED));
89 } else if (s.equals(CommonTriggerEvents.DIR2_PRESSED)) {
90 setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
91 setData((byte) ((dir2 << 5) | PRESSED));
97 protected State convertToStateImpl(String channelId, String channelTypeId,
98 Function<String, State> getCurrentStateFunc, Configuration config) {
99 // this method is used by the classic device listener channels to convert a rocker switch message into an
100 // appropriate item update
101 State currentState = getCurrentStateFunc.apply(channelId);
103 EnOceanChannelRockerSwitchListenerConfig c = config.as(EnOceanChannelRockerSwitchListenerConfig.class);
104 byte dir1 = c.getChannel() == Channel.ChannelA ? AI : BI;
105 byte dir2 = c.getChannel() == Channel.ChannelA ? A0 : B0;
107 return getState(dir1, dir2, c.handleSecondAction, c.getSwitchMode(), channelTypeId, currentState);
110 return UnDefType.UNDEF;
114 public boolean isValidForTeachIn() {
115 return false; // Never treat a message as F6-02-02, let user decide which orientation of rocker switch is used