use of org.openhab.binding.zwave.internal.converter.command.MultiLevelUpDownCommandConverter in project openhab1-addons by openhab.
the class ZWaveMultiLevelSwitchConverter method receiveCommand.
/**
* {@inheritDoc}
*/
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveMultiLevelSwitchCommandClass commandClass, int endpointId, Map<String, String> arguments) {
SerialMessage serialMessage = null;
String restoreLastValue = null;
if (command instanceof StopMoveType && (StopMoveType) command == StopMoveType.STOP) {
// special handling for the STOP command
serialMessage = commandClass.stopLevelChangeMessage();
} else {
ZWaveCommandConverter<?, ?> converter = null;
if (command instanceof OnOffType) {
restoreLastValue = arguments.get("restore_last_value");
if ("true".equalsIgnoreCase(restoreLastValue)) {
converter = this.restoreValueOnOffConverter;
} else {
converter = this.normalOnOffConverter;
}
} else {
converter = this.getCommandConverter(command.getClass());
}
if (converter == null) {
logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
// Allow inversion of roller shutter UP/DOWN
if (converter instanceof MultiLevelUpDownCommandConverter) {
logger.debug("Multilevel Switch MultiLevelUpDownCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_state"))) {
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - invert");
if (command == UpDownType.UP) {
command = UpDownType.DOWN;
} else {
command = UpDownType.UP;
}
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - inverted: {}", command);
}
}
// Allow inversion of roller shutter PERCENT value
if (converter instanceof MultiLevelPercentCommandConverter) {
logger.debug("Multilevel Switch MultiLevelPercentCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_percent"))) {
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - invert");
command = new PercentType(100 - ((DecimalType) command).intValue());
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - inverted: {}", command);
}
}
Integer value = (Integer) converter.convertFromCommandToValue(item, command);
logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), command.toString(), value, item.getName(), endpointId);
serialMessage = commandClass.setValueMessage(value);
}
// encapsulate the message in case this is a multi-instance node
serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
if (serialMessage == null) {
logger.warn("Generating message failed for command class = {}, node = {}, endpoint = {}", commandClass.getCommandClass().getLabel(), node.getNodeId(), endpointId);
return;
}
this.getController().sendData(serialMessage);
// update the bus in case of normal dimming. schedule refresh in case of restore to last value dimming.
if (!"true".equalsIgnoreCase(restoreLastValue) && command instanceof OnOffType && (OnOffType) command == OnOffType.ON) {
executeRefresh(node, commandClass, endpointId, arguments);
} else if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
Aggregations