use of org.openhab.core.types.Type 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 org.openhab.core.types.Type 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");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping2ByteUnsigned_7_004.
/**
* KNXCoreTypeMapper tests for method typeMapper.toType() type “2-Octet Unsigned Value" KNX ID: 7.004
* DPT_TIMEPERIOD_100
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping2ByteUnsigned_7_004() throws KNXFormatException {
DPT dpt = DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100;
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[] { 0x00, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0xFF, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "6528000");
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "6553500");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "6553500");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingSceneNumber_18_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Scene Number" KNX ID: 18.001 DPT_SCENE_CONTROL
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingSceneNumber_18_001() throws KNXFormatException {
DPT dpt = DPTXlatorSceneControl.DPT_SCENE_CONTROL;
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));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "learn 63");
type = testToType(dpt, new byte[] { 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "activate 0");
type = testToType(dpt, new byte[] { 0x3F }, DecimalType.class);
testToDPTValue(dpt, type, "activate 63");
// Test that the second msb (reserved) are ignored
type = testToType(dpt, new byte[] { (byte) 0xC0 }, DecimalType.class);
testToDPTValue(dpt, type, "learn 0");
// Test that the second msb (reserved) are ignored
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "learn 63");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingString.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “String" KNX ID: 16.001 DPT_STRING_8859_1
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingString() throws KNXFormatException {
DPT dpt = DPTXlatorString.DPT_STRING_8859_1;
testToTypeClass(dpt, StringType.class);
/*
* According to spec the length of this DPT is fixed to 14 bytes.
*
* Test the that a too short array results in an <null> string. There should be an error logged by calimero lib
* (V2.2.0).
*/
Type type = testToType(dpt, new byte[] { 0x61, 0x62 }, StringType.class);
testToDPTValue(dpt, type, null);
/*
* FIXME: According to spec the length of this DPT is fixed to 14 bytes. Calimero lib (V 2.2.0) isn't checking
* this correctly and has a bug in
* tuwien.auto.calimero.dptxlator.DPTXlatorString.toDPT(final byte[] buf, final int offset). Calimero accepts
* any byte array larger or equal to 14 bytes
* without error. As a result: anything less then 14 bytes and above a multiple of 14 bytes will be accepted but
* cutoff. Even for the failed check (less
* then 14 bytes) calimero is not throwing an exception but is logging an error which we cannot check for here.
*
* Test the erroneous behavior that a too long arrays result in a cutoff string. There probably won't be an
* error logged by calimero lib (V2.2.0).
*/
type = testToType(dpt, new byte[] { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F }, StringType.class);
testToDPTValue(dpt, type, "abcdefghijklmn");
/*
* Test a 14 byte array.
*/
type = testToType(dpt, new byte[] { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E }, StringType.class);
testToDPTValue(dpt, type, "abcdefghijklmn");
/*
* Test that a byte array filled with 0 and correct length is resulting in an empty string.
*/
type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, StringType.class);
testToDPTValue(dpt, type, "");
}
Aggregations