use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingColourRGB_232_600.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “3-byte RGB value" KNX ID: 232.600 DPT_Colour_RGB
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingColourRGB_232_600() throws KNXFormatException {
DPT dpt = DPTXlatorRGB.DPT_RGB;
testToTypeClass(dpt, HSBType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, HSBType.class));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0 }, HSBType.class);
testToDPTValue(dpt, type, "r:255 g:255 b:255");
// Test max value
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0 }, HSBType.class);
testToDPTValue(dpt, type, "r:255 g:255 b:255");
// Test min value
type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00 }, HSBType.class);
testToDPTValue(dpt, type, "r:0 g:0 b:0");
// Test correct interpretation of r value
type = testToType(dpt, new byte[] { (byte) 0xff, 0x00, 0x00 }, HSBType.class);
testToDPTValue(dpt, type, "r:255 g:0 b:0");
// Test correct interpretation of g value
type = testToType(dpt, new byte[] { 0x00, (byte) 0xff, 0x00 }, HSBType.class);
testToDPTValue(dpt, type, "r:0 g:255 b:0");
// Test correct interpretation of b value
type = testToType(dpt, new byte[] { 0x00, 0x00, (byte) 0xff }, HSBType.class);
testToDPTValue(dpt, type, "r:0 g:0 b:255");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingDate_11_001__ZeroMonth.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 11.001 DPT_DATE
*
* Test illegal month (cannot be 0) This should throw an KNXIllegalArgumentException
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingDate_11_001__ZeroMonth() throws KNXFormatException {
DPT dpt = DPTXlatorDate.DPT_DATE;
testToTypeClass(dpt, DateTimeType.class);
assertNull("KNXCoreTypeMapper.toType() should return null", testToType(dpt, new byte[] { 0x01, 0x00, 0x00 }, DateTimeType.class));
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping4ByteFloat_14.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “4-Octet Float Value" KNX ID: 14
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping4ByteFloat_14() throws KNXFormatException {
Locale defaultLocale = Locale.getDefault();
Locale[] locales = { defaultLocale, Locale.ENGLISH, Locale.GERMAN };
DPT[] dpts = { DPTXlator4ByteFloat.DPT_ACCELERATION_ANGULAR, DPTXlator4ByteFloat.DPT_ANGLE_DEG, DPTXlator4ByteFloat.DPT_ELECTRIC_CURRENT, DPTXlator4ByteFloat.DPT_ELECTRIC_POTENTIAL, DPTXlator4ByteFloat.DPT_FREQUENCY, DPTXlator4ByteFloat.DPT_POWER };
// Iterate over the locales
for (Locale locale : locales) {
// Iterate over the subtypes to be tested
for (DPT dpt : dpts) {
Locale.setDefault(locale);
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
try {
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "340282000000000000000000000000000000000");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0");
}
try {
Type type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "0.0");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0");
}
try {
// Test the smallest positive value
Type type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x01 }, DecimalType.class);
testToDPTValue(dpt, type, "0.0000000000000000000000000000000000000000000014");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0000000000000000000000000000000000000000000014");
}
try {
// Test the smallest negative value
Type type = testToType(dpt, new byte[] { (byte) 0x80, 0x00, 0x00, 0x01 }, DecimalType.class);
testToDPTValue(dpt, type, "-0.0000000000000000000000000000000000000000000014");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting -0.0000000000000000000000000000000000000000000014");
}
try {
// Test the maximum positive value
Type type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "340282000000000000000000000000000000000");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 340282000000000000000000000000000000000");
}
try {
// Test the maximum negative value
Type type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "-340282000000000000000000000000000000000");
} catch (NumberFormatException nfe) {
fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting -340282000000000000000000000000000000000");
}
}
}
Locale.setDefault(defaultLocale);
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_004.
/**
* KNXCoreTypeMapper tests method typeMapper.toType()for type “8-Bit Unsigned Value" KNX ID: 5.004 DPT_PERCENT_U8
* (previously name DPT_RelPos_Valve)
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitUnsigned_5_004() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_PERCENT_U8;
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { 50 }, DecimalType.class);
testToDPTValue(dpt, type, "50");
type = testToType(dpt, new byte[] { 100 }, DecimalType.class);
testToDPTValue(dpt, type, "100");
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "255");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "255");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_003.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.003 DPT_ANGLE
*
* This data type is a “Multi-state” type, according KNX spec. No exact linear conversion from value to byte(s) and
* reverse is required, since rounding is
* involved.
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitUnsigned_5_003() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_ANGLE;
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0x7F }, DecimalType.class);
testToDPTValue(dpt, type, "179");
type = testToType(dpt, new byte[] { (byte) 0x80 }, DecimalType.class);
testToDPTValue(dpt, type, "181");
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "360");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "360");
}
Aggregations