[nikobus] added option to reverse rollershutter commands (#10047)
* Added option to reverse rollershutter commands - UP -> DOWN and DOWN -> UP - might happen if rollershuter module's output is wired differently. * Fixed PR comments. Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
This commit is contained in:
parent
0d13b8d1ef
commit
6878384df9
|
@ -131,6 +131,8 @@ Defines a `rollershutter-module` with address `4C6C`.
|
||||||
| output-5 | Rollershutter | Output 5 |
|
| output-5 | Rollershutter | Output 5 |
|
||||||
| output-6 | Rollershutter | Output 6 |
|
| output-6 | Rollershutter | Output 6 |
|
||||||
|
|
||||||
|
In case rollershutters are moving in the oposite direction when sending `UP` or `DOWN` commands, there is a `reverse` parameter, which can be set to `true` in this case to reverse the rollershutter's direction. Defaults to `false`.
|
||||||
|
|
||||||
##### Estimating Position
|
##### Estimating Position
|
||||||
|
|
||||||
Nikobus rollershuter module does not provide information about rollershutter's position. In order to bridge this gap, an optional parameter `duration` can be set per channel, describing the amount of time needed by a rollershutter to get from open to closed state (or vice-versa).
|
Nikobus rollershuter module does not provide information about rollershutter's position. In order to bridge this gap, an optional parameter `duration` can be set per channel, describing the amount of time needed by a rollershutter to get from open to closed state (or vice-versa).
|
||||||
|
|
|
@ -53,16 +53,16 @@ public class NikobusDimmerModuleHandler extends NikobusSwitchModuleHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int valueFromCommand(Command command) {
|
protected int valueFromCommand(String channelId, Command command) {
|
||||||
if (command instanceof PercentType) {
|
if (command instanceof PercentType) {
|
||||||
return Math.round(((PercentType) command).floatValue() / 100f * 255f);
|
return Math.round(((PercentType) command).floatValue() / 100f * 255f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.valueFromCommand(command);
|
return super.valueFromCommand(channelId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected State stateFromValue(int value) {
|
protected State stateFromValue(String channelId, int value) {
|
||||||
int result = Math.round(value * 100f / 255f);
|
int result = Math.round(value * 100f / 255f);
|
||||||
return new PercentType(result);
|
return new PercentType(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ abstract class NikobusModuleHandler extends NikobusBaseThingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousValue == null || previousValue.intValue() != value) {
|
if (previousValue == null || previousValue.intValue() != value) {
|
||||||
updateState(channelId, stateFromValue(value));
|
updateState(channelId, stateFromValue(channelId, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ abstract class NikobusModuleHandler extends NikobusBaseThingHandler {
|
||||||
Integer digits;
|
Integer digits;
|
||||||
|
|
||||||
if (channelId.equals(channelUID.getId())) {
|
if (channelId.equals(channelUID.getId())) {
|
||||||
digits = valueFromCommand(command);
|
digits = valueFromCommand(channelId, command);
|
||||||
updateStateAndCacheValue(channelId, digits.intValue());
|
updateStateAndCacheValue(channelId, digits.intValue());
|
||||||
} else {
|
} else {
|
||||||
synchronized (cachedStates) {
|
synchronized (cachedStates) {
|
||||||
|
@ -233,7 +233,7 @@ abstract class NikobusModuleHandler extends NikobusBaseThingHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int valueFromCommand(Command command);
|
protected abstract int valueFromCommand(String channelId, Command command);
|
||||||
|
|
||||||
protected abstract State stateFromValue(int value);
|
protected abstract State stateFromValue(String channelId, int value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
package org.openhab.binding.nikobus.internal.handler;
|
package org.openhab.binding.nikobus.internal.handler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -44,6 +46,8 @@ public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
|
||||||
private final Logger logger = LoggerFactory.getLogger(NikobusRollershutterModuleHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(NikobusRollershutterModuleHandler.class);
|
||||||
private final List<PositionEstimator> positionEstimators = new CopyOnWriteArrayList<>();
|
private final List<PositionEstimator> positionEstimators = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
private final Map<String, DirectionConfiguration> directionConfigurations = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public NikobusRollershutterModuleHandler(Thing thing) {
|
public NikobusRollershutterModuleHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
}
|
}
|
||||||
|
@ -57,43 +61,50 @@ public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
positionEstimators.clear();
|
positionEstimators.clear();
|
||||||
|
directionConfigurations.clear();
|
||||||
|
|
||||||
for (Channel channel : thing.getChannels()) {
|
for (Channel channel : thing.getChannels()) {
|
||||||
PositionEstimatorConfig config = channel.getConfiguration().as(PositionEstimatorConfig.class);
|
PositionEstimatorConfig config = channel.getConfiguration().as(PositionEstimatorConfig.class);
|
||||||
if (config.delay >= 0 && config.duration > 0) {
|
if (config.delay >= 0 && config.duration > 0) {
|
||||||
positionEstimators.add(new PositionEstimator(channel.getUID(), config));
|
positionEstimators.add(new PositionEstimator(channel.getUID(), config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DirectionConfiguration configuration = config.reverse ? DirectionConfiguration.REVERSED
|
||||||
|
: DirectionConfiguration.NORMAL;
|
||||||
|
directionConfigurations.put(channel.getUID().getId(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Position estimators for {} = {}", thing.getUID(), positionEstimators);
|
logger.debug("Position estimators for {} = {}", thing.getUID(), positionEstimators);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int valueFromCommand(Command command) {
|
protected int valueFromCommand(String channelId, Command command) {
|
||||||
if (command == UpDownType.DOWN || command == StopMoveType.MOVE) {
|
|
||||||
return 0x02;
|
|
||||||
}
|
|
||||||
if (command == UpDownType.UP) {
|
|
||||||
return 0x01;
|
|
||||||
}
|
|
||||||
if (command == StopMoveType.STOP) {
|
if (command == StopMoveType.STOP) {
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
if (command == UpDownType.DOWN || command == StopMoveType.MOVE) {
|
||||||
|
return getDirectionConfiguration(channelId).down;
|
||||||
|
}
|
||||||
|
if (command == UpDownType.UP) {
|
||||||
|
return getDirectionConfiguration(channelId).up;
|
||||||
|
}
|
||||||
throw new IllegalArgumentException("Command '" + command + "' not supported");
|
throw new IllegalArgumentException("Command '" + command + "' not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected State stateFromValue(int value) {
|
protected State stateFromValue(String channelId, int value) {
|
||||||
if (value == 0x00) {
|
if (value == 0x00) {
|
||||||
return OnOffType.OFF;
|
return OnOffType.OFF;
|
||||||
}
|
}
|
||||||
if (value == 0x01) {
|
|
||||||
|
DirectionConfiguration configuration = getDirectionConfiguration(channelId);
|
||||||
|
if (value == configuration.up) {
|
||||||
return UpDownType.UP;
|
return UpDownType.UP;
|
||||||
}
|
}
|
||||||
if (value == 0x02) {
|
if (value == configuration.down) {
|
||||||
return UpDownType.DOWN;
|
return UpDownType.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unexpected value " + value + " received");
|
throw new IllegalArgumentException("Unexpected value " + value + " received");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,9 +130,18 @@ public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
|
||||||
super.updateState(channelUID, new PercentType(percent));
|
super.updateState(channelUID, new PercentType(percent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DirectionConfiguration getDirectionConfiguration(String channelId) {
|
||||||
|
DirectionConfiguration configuration = directionConfigurations.get(channelId);
|
||||||
|
if (configuration == null) {
|
||||||
|
throw new IllegalArgumentException("Direction configuration not found for " + channelId);
|
||||||
|
}
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
public static class PositionEstimatorConfig {
|
public static class PositionEstimatorConfig {
|
||||||
public int duration = -1;
|
public int duration = -1;
|
||||||
public int delay = 5;
|
public int delay = 5;
|
||||||
|
public boolean reverse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PositionEstimator {
|
private class PositionEstimator {
|
||||||
|
@ -203,4 +223,17 @@ public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
|
||||||
+ delayInMillis + "ms)";
|
+ delayInMillis + "ms)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class DirectionConfiguration {
|
||||||
|
final int up;
|
||||||
|
final int down;
|
||||||
|
|
||||||
|
final static DirectionConfiguration NORMAL = new DirectionConfiguration(1, 2);
|
||||||
|
final static DirectionConfiguration REVERSED = new DirectionConfiguration(2, 1);
|
||||||
|
|
||||||
|
private DirectionConfiguration(int up, int down) {
|
||||||
|
this.up = up;
|
||||||
|
this.down = down;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class NikobusSwitchModuleHandler extends NikobusModuleHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int valueFromCommand(Command command) {
|
protected int valueFromCommand(String channelId, Command command) {
|
||||||
if (command == OnOffType.ON) {
|
if (command == OnOffType.ON) {
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class NikobusSwitchModuleHandler extends NikobusModuleHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected State stateFromValue(int value) {
|
protected State stateFromValue(String channelId, int value) {
|
||||||
return value != 0 ? OnOffType.ON : OnOffType.OFF;
|
return value != 0 ? OnOffType.ON : OnOffType.OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@
|
||||||
<label>Delay</label>
|
<label>Delay</label>
|
||||||
<description>Delay specifying how many seconds after duration module's output is set to OFF. Defaults to 5 seconds</description>
|
<description>Delay specifying how many seconds after duration module's output is set to OFF. Defaults to 5 seconds</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
|
<parameter name="reverse" type="boolean">
|
||||||
|
<label>Reverse Direction</label>
|
||||||
|
<description>Reverse direction of rollershutters. Defaults to false</description>
|
||||||
|
</parameter>
|
||||||
</config-description>
|
</config-description>
|
||||||
|
|
||||||
</config-description:config-descriptions>
|
</config-description:config-descriptions>
|
||||||
|
|
Loading…
Reference in New Issue