Search in sources :

Example 26 with DecimalType

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

the class DmxColorItemTest method decreasesWhenDecreaseCommandReceived.

@Test
@Override
public void decreasesWhenDecreaseCommandReceived() throws BindingConfigParseException {
    DmxItem item = getValidInstance();
    DmxService service = Mockito.mock(DmxService.class);
    HSBType hsb = new HSBType(new DecimalType(150), new PercentType(50), new PercentType(50));
    item.processCommand(service, hsb);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 65);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 129);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 97);
    item.processCommand(service, IncreaseDecreaseType.DECREASE);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 57);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 116);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 87);
}
Also used : DmxService(org.openhab.binding.dmx.DmxService) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) Test(org.junit.Test)

Example 27 with DecimalType

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

the class DmxColorItemTest method increasesWhenIncreaseCommandReceived.

@Test
@Override
public void increasesWhenIncreaseCommandReceived() throws BindingConfigParseException {
    DmxItem item = getValidInstance();
    DmxService service = Mockito.mock(DmxService.class);
    HSBType hsb = new HSBType(new DecimalType(150), new PercentType(50), new PercentType(50));
    item.processCommand(service, hsb);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 65);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 129);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 97);
    item.processCommand(service, IncreaseDecreaseType.INCREASE);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 70);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 140);
    Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 106);
}
Also used : DmxService(org.openhab.binding.dmx.DmxService) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) Test(org.junit.Test)

Example 28 with DecimalType

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

the class MaxCulBinding method updateCreditMonitors.

private void updateCreditMonitors() {
    /* find and update credit monitor binding if it exists */
    int credit10ms = messageHandler.getCreditStatus();
    for (MaxCulBindingProvider provider : super.providers) {
        Collection<MaxCulBindingConfig> bindingConfigs = provider.getCreditMonitorBindings();
        for (MaxCulBindingConfig bc : bindingConfigs) {
            String itemName = provider.getItemNameForConfig(bc);
            eventPublisher.postUpdate(itemName, new DecimalType(credit10ms));
        }
    }
}
Also used : MaxCulBindingProvider(org.openhab.binding.maxcul.MaxCulBindingProvider) DecimalType(org.openhab.core.library.types.DecimalType)

Example 29 with DecimalType

use of org.openhab.core.library.types.DecimalType 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 30 with DecimalType

use of org.openhab.core.library.types.DecimalType 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)

Aggregations

DecimalType (org.openhab.core.library.types.DecimalType)222 Test (org.junit.Test)70 StringType (org.openhab.core.library.types.StringType)69 OnOffType (org.openhab.core.library.types.OnOffType)63 PercentType (org.openhab.core.library.types.PercentType)43 State (org.openhab.core.types.State)40 Type (org.openhab.core.types.Type)39 NumberItem (org.openhab.core.library.items.NumberItem)38 SHCMessage (org.openhab.binding.smarthomatic.internal.SHCMessage)37 DateTimeType (org.openhab.core.library.types.DateTimeType)29 BigDecimal (java.math.BigDecimal)23 Calendar (java.util.Calendar)23 HSBType (org.openhab.core.library.types.HSBType)20 SwitchItem (org.openhab.core.library.items.SwitchItem)18 IOException (java.io.IOException)16 StringItem (org.openhab.core.library.items.StringItem)16 ConfigurationException (org.osgi.service.cm.ConfigurationException)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ContactItem (org.openhab.core.library.items.ContactItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)14