Skip to content

Commit

Permalink
* Added new channels for RockerSwitches
Browse files Browse the repository at this point in the history
   * secondActionPressed: indicates if second action is pressed too
   * rockerSwitchAction: Emits combined RockerSwitch actions (ChannelADirection|ChannelBDirection), has two filters to control when this channel should trigger, channel is extensible
* Added two profiles for new channel rockerSwitchAction
  * rockerswitchaction-toggle-switch: toggles a switch item if channel rockerSwitchAction triggers
  * rockerswitchaction-toggle-player: toggles a player item if channel rockerSwitchAction triggers
* EnOceanBaseSensorHandler can now handle extensible channels too
* Refactoring of F6_02 EEP
  • Loading branch information
fruggy83 committed Sep 2, 2021
1 parent 1cc175d commit 8cd76e5
Show file tree
Hide file tree
Showing 13 changed files with 673 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public class EnOceanBindingConstants {

public static final String CHANNEL_ROCKERSWITCH_CHANNELA = "rockerswitchA";
public static final String CHANNEL_ROCKERSWITCH_CHANNELB = "rockerswitchB";
public static final String CHANNEL_ROCKERSWITCH_SECONDACTIONPRESSED = "secondActionPressed";
public static final String CHANNEL_ROCKERSWITCH_ACTION = "rockerSwitchAction";
public static final ChannelTypeUID CHANNELTYPE_ROCKERSWITCH_ACTION_UID = new ChannelTypeUID(BINDING_ID,
CHANNEL_ROCKERSWITCH_ACTION);

public static final String CHANNEL_VIRTUALSWITCHA = "virtualSwitchA";
public static final String CHANNEL_VIRTUALROLLERSHUTTERA = "virtualRollershutterA";
Expand Down Expand Up @@ -356,6 +360,13 @@ public class EnOceanBindingConstants {
Map.entry(CHANNEL_ROCKERSWITCH_CHANNELB,
new EnOceanChannelDescription(DefaultSystemChannelTypeProvider.SYSTEM_RAWROCKER.getUID(), null,
"Rocker Switch - Channel B", false, false)),
Map.entry(CHANNEL_ROCKERSWITCH_SECONDACTIONPRESSED,
new EnOceanChannelDescription(
new ChannelTypeUID(BINDING_ID, CHANNEL_ROCKERSWITCH_SECONDACTIONPRESSED),
CoreItemFactory.SWITCH, "Second Action Pressed", false, false)),
Map.entry(CHANNEL_ROCKERSWITCH_ACTION,
new EnOceanChannelDescription(CHANNELTYPE_ROCKERSWITCH_ACTION_UID, null, "Rocker Switch Action",
false, false)),

Map.entry(CHANNEL_VIRTUALSWITCHA,
new EnOceanChannelDescription(new ChannelTypeUID(BINDING_ID, CHANNEL_VIRTUALSWITCHA),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enocean.internal.config;

/**
*
* @author Daniel Weber - Initial contribution
*/
public class EnOceanChannelRockerSwitchActionConfig {

public String channelAFilter;
public String channelBFilter;

public EnOceanChannelRockerSwitchActionConfig() {
channelAFilter = "*";
channelBFilter = "*";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,15 @@ public enum EEPType {
CHANNEL_DOUBLEPRESS, CHANNEL_LONGPRESS, CHANNEL_BATTERY_LEVEL),

RockerSwitch2RockerStyle1(RORG.RPS, 0x02, 0x01, false, F6_02_01.class, THING_TYPE_ROCKERSWITCH,
CHANNEL_ROCKERSWITCH_CHANNELA, CHANNEL_ROCKERSWITCH_CHANNELB, CHANNEL_VIRTUALSWITCHA,
CHANNEL_VIRTUALROLLERSHUTTERA, CHANNEL_VIRTUALROCKERSWITCHB, CHANNEL_ROCKERSWITCHLISTENERSWITCH,
CHANNEL_ROCKERSWITCH_CHANNELA, CHANNEL_ROCKERSWITCH_CHANNELB, CHANNEL_ROCKERSWITCH_SECONDACTIONPRESSED,
CHANNEL_ROCKERSWITCH_ACTION, CHANNEL_VIRTUALSWITCHA, CHANNEL_VIRTUALROLLERSHUTTERA,
CHANNEL_VIRTUALROCKERSWITCHB, CHANNEL_ROCKERSWITCHLISTENERSWITCH,
CHANNEL_ROCKERSWITCHLISTENERROLLERSHUTTER),

RockerSwitch2RockerStyle2(RORG.RPS, 0x02, 0x02, false, F6_02_02.class, THING_TYPE_ROCKERSWITCH,
CHANNEL_ROCKERSWITCH_CHANNELA, CHANNEL_ROCKERSWITCH_CHANNELB, CHANNEL_VIRTUALSWITCHA,
CHANNEL_VIRTUALROLLERSHUTTERA, CHANNEL_VIRTUALROCKERSWITCHB, CHANNEL_ROCKERSWITCHLISTENERSWITCH,
CHANNEL_ROCKERSWITCH_CHANNELA, CHANNEL_ROCKERSWITCH_CHANNELB, CHANNEL_ROCKERSWITCH_SECONDACTIONPRESSED,
CHANNEL_ROCKERSWITCH_ACTION, CHANNEL_VIRTUALSWITCHA, CHANNEL_VIRTUALROLLERSHUTTERA,
CHANNEL_VIRTUALROCKERSWITCHB, CHANNEL_ROCKERSWITCHLISTENERSWITCH,
CHANNEL_ROCKERSWITCHLISTENERROLLERSHUTTER),

MechanicalHandle00(RORG.RPS, 0x10, 0x00, false, F6_10_00.class, THING_TYPE_MECHANICALHANDLE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enocean.internal.eep.F6_02;

import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchActionConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.UpDownType;
import org.openhab.core.thing.CommonTriggerEvents;
import org.openhab.core.types.State;

/**
*
* @author Daniel Weber - Initial contribution
*/
public abstract class F6_02 extends _RPSMessage {

final byte AI = 0;
final byte A0 = 1;
final byte BI = 2;
final byte B0 = 3;
final byte PRESSED = 16;
final byte PRESSED_SEC = 1;

final String DIR1 = "DIR1";
final String DIR2 = "DIR2";
final String ANYDIR = "*";
final String NODIR = "-";

int secondByte = -1;
int secondStatus = -1;

public F6_02() {
super();
}

public F6_02(ERP1Message packet) {
super(packet);
}

private String getChannelADir() {
if ((bytes[0] >>> 5) == A0 && (bytes[0] & PRESSED) != 0) {
return DIR1;
} else if ((bytes[0] >>> 5) == AI && (bytes[0] & PRESSED) != 0) {
return DIR2;
} else {
return NODIR;
}
}

private String getChannelBDir() {
if ((bytes[0] >>> 5) == B0 && (bytes[0] & PRESSED) != 0) {
return DIR1;
} else if ((bytes[0] >>> 5) == BI && (bytes[0] & PRESSED) != 0) {
return DIR2;
} else if (((bytes[0] & 0xf) >>> 1) == B0 && (bytes[0] & PRESSED_SEC) != 0) {
return DIR1;
} else if (((bytes[0] & 0xf) >>> 1) == BI && (bytes[0] & PRESSED_SEC) != 0) {
return DIR2;
} else {
return NODIR;
}
}

protected String getRockerSwitchAction(Configuration config) {
EnOceanChannelRockerSwitchActionConfig conf = config.as(EnOceanChannelRockerSwitchActionConfig.class);
String dirA = getChannelADir();
String dirB = getChannelBDir();

if (!(conf.channelAFilter.equals(ANYDIR) || conf.channelAFilter.equals(dirA))) {
return null;
} else if (!(conf.channelBFilter.equals(ANYDIR) || conf.channelBFilter.equals(dirB))) {
return null;
} else {
return dirA + "|" + dirB;
}
}

protected String getChannelEvent(byte dir1, byte dir2) {
if ((bytes[0] >>> 5) == dir1) {
return ((bytes[0] & PRESSED) != 0) ? CommonTriggerEvents.DIR1_PRESSED : CommonTriggerEvents.DIR1_RELEASED;
} else if ((bytes[0] >>> 5) == dir2) {
return ((bytes[0] & PRESSED) != 0) ? CommonTriggerEvents.DIR2_PRESSED : CommonTriggerEvents.DIR2_RELEASED;
} else if (((bytes[0] & 0xf) >>> 1) == dir1) {
return ((bytes[0] & PRESSED_SEC) != 0) ? CommonTriggerEvents.DIR1_PRESSED
: CommonTriggerEvents.DIR1_RELEASED;
} else if (((bytes[0] & 0xf) >>> 1) == dir2) {
return ((bytes[0] & PRESSED_SEC) != 0) ? CommonTriggerEvents.DIR2_PRESSED
: CommonTriggerEvents.DIR2_RELEASED;
} else {
return null;
}
}

protected State inverse(OnOffType currentState) {
return currentState == OnOffType.ON ? OnOffType.OFF : OnOffType.ON;
}

protected State inverse(UpDownType currentState) {
return currentState == UpDownType.UP ? UpDownType.DOWN : UpDownType.UP;
}

@Override
protected boolean validateData(byte[] bytes) {
return super.validateData(bytes) && !getBit(bytes[0], 7);
}
}
Loading

0 comments on commit 8cd76e5

Please sign in to comment.