Skip to content

Commit

Permalink
[lcn] Add ability to invert Rollershutter Up/Down (#8051)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Wolter <[email protected]>
  • Loading branch information
fwolter authored Jul 1, 2020
1 parent 5872892 commit a625f41
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.binding.lcn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ If a special command is needed, the [Hit Key](#hit-key) action (German: "Sende T

S0 counter Channels need to be the pulses per kWh configured. If the value is left blank, a default value of 1000 pulses/kWh is set.

The Rollershutter Channels provide the boolean parameter `invertUpDown`, which can be set to 'true' if the Up/Down wires are interchanged.

### Transponder

LCN transponder readers can be integrated in openHAB e.g. for access control.
Expand Down
4 changes: 3 additions & 1 deletion bundles/org.openhab.binding.lcn/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ public void handleCommand(ChannelUID channelUid, Command command) {
DecimalType nativeValue = getConverter(channelUid).onCommandFromItem(quantityType);
subHandler.handleCommandDecimal(nativeValue, channelGroup, number.get());
} else if (command instanceof UpDownType) {
subHandler.handleCommandUpDown((UpDownType) command, channelGroup, number.get());
Channel channel = thing.getChannel(channelUid);
if (channel != null) {
Object invertConfig = channel.getConfiguration().get("invertUpDown");
boolean invertUpDown = invertConfig instanceof Boolean && (boolean) invertConfig;
subHandler.handleCommandUpDown((UpDownType) command, channelGroup, number.get(), invertUpDown);
}
} else if (command instanceof StopMoveType) {
subHandler.handleCommandStopMove((StopMoveType) command, channelGroup, number.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public void handleCommandString(StringType command, int number) throws LcnExcept
}

@Override
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number) throws LcnException {
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number, boolean invertUpDown)
throws LcnException {
unsupportedCommand(command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ void handleCommandPercent(PercentType command, LcnChannelGroup channelGroup, Str
* @param command the command to handle
* @param channelGroup the addressed Channel group
* @param number the Channel's number within the Channel group
* @param invertUpDown true, if Up/Down is inverted
* @throws LcnException when the command could not processed
*/
void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number) throws LcnException;
void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number, boolean invertUpDown)
throws LcnException;

/**
* Handles a Command from openHAB.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public void handleRefresh(LcnChannelGroup channelGroup, int number) {
}

@Override
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number) throws LcnException {
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number, boolean invertUpDown)
throws LcnException {
// When configured as shutter in LCN-PRO, an output gets switched off, when the other is
// switched on and vice versa.
if (command == UpDownType.UP) {
if (command == UpDownType.UP ^ invertUpDown) {
// first output: 100%
handler.sendPck(PckGenerator.dimOutput(0, 100, LcnDefs.ROLLER_SHUTTER_RAMP_MS));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* Handles Commands and State changes of roller shutters connected to relays of an LCN module.
*
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
Expand All @@ -45,10 +45,11 @@ public void handleRefresh(LcnChannelGroup channelGroup, int number) {
}

@Override
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number) throws LcnException {
public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number, boolean invertUpDown)
throws LcnException {
RelayStateModifier[] relayStateModifiers = createRelayStateModifierArray();
// direction relay
relayStateModifiers[number * 2 + 1] = command == UpDownType.DOWN ? LcnDefs.RelayStateModifier.ON
relayStateModifiers[number * 2 + 1] = command == UpDownType.DOWN ^ invertUpDown ? LcnDefs.RelayStateModifier.ON
: LcnDefs.RelayStateModifier.OFF;
// power relay
relayStateModifiers[number * 2] = LcnDefs.RelayStateModifier.ON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
<item-type>Rollershutter</item-type>
<label>Roller Shutter</label>
<autoUpdatePolicy>veto</autoUpdatePolicy>
<config-description>
<parameter name="invertUpDown" type="boolean">
<label>Invert Up/Down</label>
<description>According LCN spec., the Up wire is connected to the "normally open" contact/Output 1. Use this
parameter to invert that logic.</description>
<default>false</default>
</parameter>
</config-description>
</channel-type>

<channel-group-type id="rollershutterrelays">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,28 @@ public void setUp() {

@Test
public void testUp() throws LcnException {
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0);
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0, false);
verify(handler).sendPck("A1DI100008");
}

@Test
public void testUpInverted() throws LcnException {
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0, true);
verify(handler).sendPck("A2DI100008");
}

@Test
public void testDown() throws LcnException {
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0);
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0, false);
verify(handler).sendPck("A2DI100008");
}

@Test
public void testDownInverted() throws LcnException {
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0, true);
verify(handler).sendPck("A1DI100008");
}

@Test
public void testStop() throws LcnException {
l.handleCommandStopMove(StopMoveType.STOP, LcnChannelGroup.ROLLERSHUTTEROUTPUT, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,37 @@ public void setUp() {

@Test
public void testUp1() throws LcnException {
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, false);
verify(handler).sendPck("R810------");
}

@Test
public void testUpInverted() throws LcnException {
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, true);
verify(handler).sendPck("R811------");
}

@Test
public void testUp4() throws LcnException {
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 3);
l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 3, false);
verify(handler).sendPck("R8------10");
}

@Test
public void testDown1() throws LcnException {
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, false);
verify(handler).sendPck("R811------");
}

@Test
public void testDownInverted() throws LcnException {
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, true);
verify(handler).sendPck("R810------");
}

@Test
public void testDown4() throws LcnException {
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 3);
l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 3, false);
verify(handler).sendPck("R8------11");
}

Expand Down

0 comments on commit a625f41

Please sign in to comment.