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);
}
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);
}
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));
}
}
}
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));
}
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));
}
Aggregations