From 4433eb025df240216aff83c1adae811069f7639e Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Wed, 1 Jul 2020 21:51:34 +0200 Subject: [PATCH] [lcn] Add ability to invert Rollershutter Up/Down (#8051) Signed-off-by: Fabian Wolter Signed-off-by: MPH80 --- bundles/org.openhab.binding.lcn/README.md | 2 ++ bundles/org.openhab.binding.lcn/pom.xml | 4 +++- .../lcn/internal/LcnModuleHandler.java | 7 ++++++- .../AbstractLcnModuleSubHandler.java | 3 ++- .../subhandler/ILcnModuleSubHandler.java | 4 +++- ...cnModuleRollershutterOutputSubHandler.java | 5 +++-- ...LcnModuleRollershutterRelaySubHandler.java | 7 ++++--- .../resources/ESH-INF/thing/thing-types.xml | 8 ++++++++ ...duleRollershutterOutputSubHandlerTest.java | 16 +++++++++++++-- ...oduleRollershutterRelaySubHandlerTest.java | 20 +++++++++++++++---- 10 files changed, 61 insertions(+), 15 deletions(-) diff --git a/bundles/org.openhab.binding.lcn/README.md b/bundles/org.openhab.binding.lcn/README.md index 6226424c7e662..1d99f8e427c0e 100644 --- a/bundles/org.openhab.binding.lcn/README.md +++ b/bundles/org.openhab.binding.lcn/README.md @@ -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. diff --git a/bundles/org.openhab.binding.lcn/pom.xml b/bundles/org.openhab.binding.lcn/pom.xml index 9819d1149049b..ae8894d181b55 100644 --- a/bundles/org.openhab.binding.lcn/pom.xml +++ b/bundles/org.openhab.binding.lcn/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java index 32ea98c7e35b3..6fd07bb345161 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java @@ -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 { diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/AbstractLcnModuleSubHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/AbstractLcnModuleSubHandler.java index 3988283d50305..869b147394065 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/AbstractLcnModuleSubHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/AbstractLcnModuleSubHandler.java @@ -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); } diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/ILcnModuleSubHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/ILcnModuleSubHandler.java index aff33cc1f0ebd..c963796fe8263 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/ILcnModuleSubHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/ILcnModuleSubHandler.java @@ -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. diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandler.java index 71b7521ebcd93..ae3960d755316 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandler.java @@ -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 { diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandler.java index ef46add8a5f01..ce701f8b4fde0 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandler.java @@ -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 @@ -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; diff --git a/bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml index 7921cd5534715..d35174ae235cd 100644 --- a/bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml @@ -151,6 +151,14 @@ Rollershutter veto + + + + According LCN spec., the Up wire is connected to the "normally open" contact/Output 1. Use this + parameter to invert that logic. + false + + diff --git a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandlerTest.java b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandlerTest.java index 3809f0a099788..b0745ea058ffb 100644 --- a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandlerTest.java +++ b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterOutputSubHandlerTest.java @@ -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); diff --git a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandlerTest.java b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandlerTest.java index 99816dc13d055..806aeb69ffb5a 100644 --- a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandlerTest.java +++ b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRollershutterRelaySubHandlerTest.java @@ -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"); }