Search in sources :

Example 1 with MultiLevelUpDownCommandConverter

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);
    }
}
Also used : MultiLevelUpDownCommandConverter(org.openhab.binding.zwave.internal.converter.command.MultiLevelUpDownCommandConverter) OnOffType(org.openhab.core.library.types.OnOffType) State(org.openhab.core.types.State) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) PercentType(org.openhab.core.library.types.PercentType) StopMoveType(org.openhab.core.library.types.StopMoveType) MultiLevelPercentCommandConverter(org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)

Aggregations

MultiLevelPercentCommandConverter (org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)1 MultiLevelUpDownCommandConverter (org.openhab.binding.zwave.internal.converter.command.MultiLevelUpDownCommandConverter)1 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)1 OnOffType (org.openhab.core.library.types.OnOffType)1 PercentType (org.openhab.core.library.types.PercentType)1 StopMoveType (org.openhab.core.library.types.StopMoveType)1 State (org.openhab.core.types.State)1