Search in sources :

Example 21 with Command

use of org.openhab.core.types.Command in project openhab1-addons by openhab.

the class FibaroFGRM222Converter method receiveCommand.

@Override
void receiveCommand(final Item item, final Command command, final ZWaveNode node, final FibaroFGRM222CommandClass commandClass, final int endpointId, final Map<String, String> arguments) {
    logger.debug("NODE {}: receiveCommand()", node.getNodeId());
    Command internalCommand = command;
    SerialMessage serialMessage = null;
    if (internalCommand instanceof StopMoveType && (StopMoveType) internalCommand == StopMoveType.STOP) {
        // special handling for the STOP command
        serialMessage = commandClass.stopLevelChangeMessage(arguments.get("type"));
    } else {
        ZWaveCommandConverter<?, ?> 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;
        }
        if (converter instanceof MultiLevelPercentCommandConverter) {
            internalCommand = new PercentType(100 - ((DecimalType) command).intValue());
        }
        Integer value = (Integer) converter.convertFromCommandToValue(item, internalCommand);
        if (value == 0) {
            value = 1;
        }
        logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), internalCommand.toString(), value, item.getName(), endpointId);
        serialMessage = commandClass.setValueMessage(value, arguments.get("type"));
    }
    // encapsulate the message in case this is a multi-instance node
    serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
    if (serialMessage == null) {
        logger.warn("NODE {}: Generating message failed for command class = {}, node = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId);
        return;
    }
    this.getController().sendData(serialMessage);
    if (command instanceof State) {
        this.getEventPublisher().postUpdate(item.getName(), (State) command);
    }
}
Also used : Command(org.openhab.core.types.Command) 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)

Example 22 with Command

use of org.openhab.core.types.Command in project openhab1-addons by openhab.

the class WriteRegistersTestParameters method generateNumberItemInt16.

/*-
     * Tests
     * - writing 12345
     * - writing -12345
     * - writing 12345.5
     * - writing -12345.5
     *
     * All tests are run with these combinations
     * - holding register or input register
     * - int16 or uint16
     * - any other combination introduced by generateParameters
     *
     * @param parameters
     */
private static void generateNumberItemInt16(List<Object[]> parameters) {
    /* int16 */
    Command[] decimal_12345 = new Command[] { new DecimalType(12345) };
    Command[] decimal_minus_12345 = new Command[] { new DecimalType(-12345) };
    // -12345 int16 = 53191 uint16
    Command[] decimal_53191 = new Command[] { new DecimalType(53191) };
    // 0x3039;
    short[] reg_int16_12345 = new short[] { 0x3039 };
    short[] reg_uint16_12345 = reg_int16_12345;
    // 0xCFC7;
    short[] reg_int16_minus_12345 = new short[] { (short) 0xCFC7 };
    // 0xCFC7
    short[] reg_uint16_minus_12345 = reg_int16_minus_12345;
    Command[] decimal_12345_pt_5 = new Command[] { new DecimalType(12345.5) };
    Command[] decimal_minus_12345_pt_5 = new Command[] { new DecimalType(-12345.5) };
    // positive
    for (Command command : Arrays.asList(decimal_12345[0], decimal_12345_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(// if
        new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if
        new DecimalType(.0), // if
        reg_int16_12345, // if
        false, // failure
        new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT16 }, new Command[] { command }));
    }
    // negative
    for (Command command : Arrays.asList(decimal_minus_12345[0], decimal_minus_12345_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if true expecting failure
        new DecimalType(.0), // if true expecting failure
        reg_int16_minus_12345, // if true expecting failure
        false, new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT16 }, new Command[] { command }));
    }
    // overflow
    parameters.addAll(WriteRegistersTestParameters.generateParameters(// if
    new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if
    new DecimalType(.0), // if
    reg_int16_minus_12345, // if
    false, // failure
    new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT16 }, decimal_53191));
    // positive
    for (Command command : Arrays.asList(decimal_12345[0], decimal_12345_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(// if
        new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if
        new DecimalType(.0), // if
        reg_uint16_12345, // if
        false, // failure
        new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT16 }, new Command[] { command }));
    }
    // negative
    for (Command command : Arrays.asList(decimal_minus_12345[0], decimal_minus_12345_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if true expecting failure
        new DecimalType(.0), // if true expecting failure
        reg_uint16_minus_12345, // if true expecting failure
        false, new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT16 }, new Command[] { command }));
    }
    // overflow
    parameters.addAll(WriteRegistersTestParameters.generateParameters(// if
    new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // if
    new DecimalType(.0), // if
    reg_uint16_minus_12345, // if
    false, // failure
    new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT16 }, decimal_53191));
}
Also used : Command(org.openhab.core.types.Command) DecimalType(org.openhab.core.library.types.DecimalType)

Example 23 with Command

use of org.openhab.core.types.Command in project openhab1-addons by openhab.

the class WriteRegistersTestParameters method generateNumberItemInt32.

/*-
     * - writing 12345678
     * - writing -12345678
     * - writing 12345678.5
     * - writing -12345678.5
     *
     * All tests are run with these combinations
     * - holding register or input register
     * - int32 or uint32
     * - any other combination introduced by generateParameters
     *
     * @param parameters
     */
private static void generateNumberItemInt32(List<Object[]> parameters) {
    /* int32 */
    Command[] decimal_12345678 = new Command[] { new DecimalType(12345678) };
    Command[] decimal_minus_12345678 = new Command[] { new DecimalType(-12345678) };
    // -12345678 int32 = 4282621618 uint32
    Command[] decimal_4282621618 = new Command[] { new DecimalType(4282621618L) };
    // 0x00BC614E;
    short[] reg_int32_12345678 = new short[] { 0x00BC, 0x614E };
    short[] reg_uint32_12345678 = reg_int32_12345678;
    // 0xFF439EB2;
    short[] reg_int32_minus_12345678 = new short[] { 0x00BC, 0x614E };
    // 0xFF439EB2
    short[] reg_uint32_minus_12345678 = reg_int32_minus_12345678;
    Command[] decimal_12345678_pt_5 = new Command[] { new DecimalType(12345678.5) };
    Command[] decimal_minus_12345678_pt_5 = new Command[] { new DecimalType(-12345678.5) };
    for (Command command : Arrays.asList(decimal_12345678[0], decimal_12345678_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(// true
        new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true
        new DecimalType(.0), // true
        reg_int32_12345678, // true
        false, // failure
        new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT32 }, new Command[] { command }));
    }
    for (Command command : Arrays.asList(decimal_minus_12345678[0], decimal_minus_12345678_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true -> exptected failure
        new DecimalType(.0), // true -> exptected failure
        reg_int32_minus_12345678, // true -> exptected failure
        false, new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT32 }, new Command[] { command }));
    }
    parameters.addAll(WriteRegistersTestParameters.generateParameters(// true
    new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true
    new DecimalType(.0), // true
    reg_int32_minus_12345678, // true
    false, // failure
    new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_INT32 }, decimal_4282621618));
    /* uint32 */
    for (Command command : Arrays.asList(decimal_12345678[0], decimal_12345678_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(// true
        new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true
        new DecimalType(.0), // true
        reg_uint32_12345678, // true
        false, // failure
        new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT32 }, new Command[] { command }));
    }
    for (Command command : Arrays.asList(decimal_minus_12345678[0], decimal_minus_12345678_pt_5[0])) {
        parameters.addAll(WriteRegistersTestParameters.generateParameters(new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true -> exptected failure
        new DecimalType(.0), // true -> exptected failure
        reg_uint32_minus_12345678, // true -> exptected failure
        false, new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT32 }, new Command[] { command }));
    }
    parameters.addAll(WriteRegistersTestParameters.generateParameters(new short[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, // true -> exptected failure
    new DecimalType(.0), // true -> exptected failure
    reg_uint32_minus_12345678, // true -> exptected failure
    false, new String[] { ModbusBindingProvider.TYPE_INPUT, ModbusBindingProvider.TYPE_HOLDING }, new String[] { ModbusBindingProvider.VALUE_TYPE_UINT32 }, decimal_4282621618));
}
Also used : Command(org.openhab.core.types.Command) DecimalType(org.openhab.core.library.types.DecimalType)

Example 24 with Command

use of org.openhab.core.types.Command in project openhab1-addons by openhab.

the class PlugwiseGenericBindingProvider method getItemNames.

@Override
public Set<String> getItemNames(String plugwiseID, PlugwiseCommandType type) {
    Set<String> result = new HashSet<String>();
    Collection<String> items = getItemNames();
    Iterator<String> itemIterator = items.iterator();
    while (itemIterator.hasNext()) {
        String anItem = itemIterator.next();
        PlugwiseBindingConfig pbConfig = (PlugwiseBindingConfig) bindingConfigs.get(anItem);
        for (Command command : pbConfig.keySet()) {
            PlugwiseBindingConfigElement element = pbConfig.get(command);
            if (element.getCommandType() == type && element.getId().equals(plugwiseID)) {
                if (!result.contains(anItem)) {
                    result.add(anItem);
                }
            }
        }
    }
    return result;
}
Also used : Command(org.openhab.core.types.Command) HashSet(java.util.HashSet)

Example 25 with Command

use of org.openhab.core.types.Command in project openhab1-addons by openhab.

the class PlugwiseGenericBindingProvider method getAllCommands.

@Override
public List<Command> getAllCommands(String itemName) {
    List<Command> commands = new ArrayList<Command>();
    PlugwiseBindingConfig config = (PlugwiseBindingConfig) bindingConfigs.get(itemName);
    for (Command command : config.keySet()) {
        commands.add(command);
    }
    return commands;
}
Also used : Command(org.openhab.core.types.Command) ArrayList(java.util.ArrayList)

Aggregations

Command (org.openhab.core.types.Command)61 ArrayList (java.util.ArrayList)20 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)14 State (org.openhab.core.types.State)12 Matcher (java.util.regex.Matcher)10 DecimalType (org.openhab.core.library.types.DecimalType)8 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)6 NikobusCommand (org.openhab.binding.nikobus.internal.core.NikobusCommand)6 SchedulerException (org.quartz.SchedulerException)6 StringType (org.openhab.core.library.types.StringType)5 JobDataMap (org.quartz.JobDataMap)5 JobDetail (org.quartz.JobDetail)5 Scheduler (org.quartz.Scheduler)5 Trigger (org.quartz.Trigger)5 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 IOException (java.io.IOException)4 SocketChannel (java.nio.channels.SocketChannel)4 IllegalClassException (org.apache.commons.lang.IllegalClassException)4 PercentType (org.openhab.core.library.types.PercentType)4