-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…0769) * Added new channel: * secondActionPressed: Indicates if second action of rocker switch is pressed too * Added two new profiles for channel rockerSwitchAction: * rockerswitchaction-toggle-switch * rockerswitchaction-toggle-player * EnOceanSensorHandler can now handle extensible channels too * EEP F6-02 refactoring Also-by: Dietmar Franzen <[email protected]> Signed-off-by: Daniel Weber <[email protected]>
- Loading branch information
1 parent
cc92423
commit 4b13a26
Showing
17 changed files
with
656 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...a/org/openhab/binding/enocean/internal/config/EnOceanProfileRockerSwitchActionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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; | ||
|
||
/** | ||
* This {@link EnOceanProfileRockerSwitchActionConfig} config class is used for rockerSwitchAction profiles to define in | ||
* which case it should react. | ||
* | ||
* @author Daniel Weber - Initial contribution | ||
*/ | ||
public class EnOceanProfileRockerSwitchActionConfig { | ||
|
||
public String channelAFilter; | ||
public String channelBFilter; | ||
|
||
public EnOceanProfileRockerSwitchActionConfig() { | ||
channelAFilter = "*"; | ||
channelBFilter = "*"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
...b.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/** | ||
* 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 static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*; | ||
|
||
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.SwitchMode; | ||
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; | ||
import org.openhab.core.types.UnDefType; | ||
|
||
/** | ||
* | ||
* @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 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) { | ||
String dirA = getChannelADir(); | ||
String dirB = getChannelBDir(); | ||
|
||
return dirA + "|" + dirB; | ||
} | ||
|
||
protected String getChannelEvent(byte dir1, byte dir2) { | ||
if ((bytes[0] & PRESSED_SEC) != 0) { | ||
// Do not emit an event if channelA is pressed together with channelB as it is undetermined which one gets | ||
// fired first | ||
return null; | ||
} else 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 { | ||
return null; | ||
} | ||
} | ||
|
||
protected State getState(byte dir1, byte dir2, boolean handleSecondAction, SwitchMode switchMode, | ||
String channelTypeId, State currentState) { | ||
// We are just listening on the pressed event here | ||
switch (switchMode) { | ||
case RockerSwitch: | ||
if ((bytes[0] >>> 5) == dir1) { | ||
if (((bytes[0] & PRESSED) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) ? OnOffType.ON : UpDownType.UP; | ||
} | ||
} else if ((bytes[0] >>> 5) == dir2) { | ||
if (((bytes[0] & PRESSED) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) ? OnOffType.OFF | ||
: UpDownType.DOWN; | ||
} | ||
} else if (handleSecondAction && ((bytes[0] & 0xf) >>> 1) == dir1) { | ||
if (((bytes[0] & PRESSED_SEC) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) ? OnOffType.ON : UpDownType.UP; | ||
} | ||
} else if (handleSecondAction && ((bytes[0] & 0xf) >>> 1) == dir2) { | ||
if (((bytes[0] & PRESSED_SEC) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) ? OnOffType.OFF | ||
: UpDownType.DOWN; | ||
} | ||
} | ||
break; | ||
case ToggleDir1: | ||
if ((bytes[0] >>> 5) == dir1) { | ||
if (((bytes[0] & PRESSED) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) | ||
? (currentState == UnDefType.UNDEF ? OnOffType.ON : inverse((OnOffType) currentState)) | ||
: (currentState == UnDefType.UNDEF ? UpDownType.UP | ||
: inverse((UpDownType) currentState)); | ||
} | ||
} else if (handleSecondAction && ((bytes[0] & 0xf) >>> 1) == dir1) { | ||
if (((bytes[0] & PRESSED_SEC) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) | ||
? (currentState == UnDefType.UNDEF ? OnOffType.ON : inverse((OnOffType) currentState)) | ||
: (currentState == UnDefType.UNDEF ? UpDownType.UP | ||
: inverse((UpDownType) currentState)); | ||
} | ||
} | ||
break; | ||
case ToggleDir2: | ||
if ((bytes[0] >>> 5) == dir2) { | ||
if (((bytes[0] & PRESSED) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) | ||
? (currentState == UnDefType.UNDEF ? OnOffType.ON : inverse((OnOffType) currentState)) | ||
: (currentState == UnDefType.UNDEF ? UpDownType.UP | ||
: inverse((UpDownType) currentState)); | ||
} | ||
} else if (handleSecondAction && ((bytes[0] & 0xf) >>> 1) == dir2) { | ||
if (((bytes[0] & PRESSED_SEC) != 0)) { | ||
return channelTypeId.equals(CHANNEL_ROCKERSWITCHLISTENERSWITCH) | ||
? (currentState == UnDefType.UNDEF ? OnOffType.ON : inverse((OnOffType) currentState)) | ||
: (currentState == UnDefType.UNDEF ? UpDownType.UP | ||
: inverse((UpDownType) currentState)); | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return UnDefType.UNDEF; | ||
} | ||
|
||
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); | ||
} | ||
} |
Oops, something went wrong.