use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_010.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.010
* DPT_VALUE_1_UCOUNT
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitUnsigned_5_010() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_VALUE_1_UCOUNT;
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) 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 testTypeMapping8BitSigned_6_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Signed Value" KNX ID: 6.001
* DPT_PERCENT_V8
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitSigned_6_001() throws KNXFormatException {
DPT dpt = DPTXlator8BitSigned.DPT_PERCENT_V8;
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, "127");
type = testToType(dpt, new byte[] { (byte) 0x80 }, DecimalType.class);
testToDPTValue(dpt, type, "-128");
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "-1");
// 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, "-1");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingDateTime_19_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Date Time" KNX ID: 19.001 DPT_DATE_TIME
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingDateTime_19_001() throws KNXFormatException {
DPT dpt = DPTXlatorDateTime.DPT_DATE_TIME;
testToTypeClass(dpt, DateTimeType.class);
assertNull("KNXCoreTypeMapper.toType() should return null (no-day)", testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, DateTimeType.class));
assertNull("KNXCoreTypeMapper.toType() should return null (illegal date)", testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, DateTimeType.class));
/*
* Reference testcase
* Monday, January 1st, 1900 01:02:03, Fault: Normal (no fault), Working Day: Bank day (No working day), Working
* Day Field: valid,
* Year Field valid, Months and Day fields valid, Day of week field valid, Hour of day, Minutes and Seconds
* fields valid,
* Standard Summer Time: Time = UT+X, Quality of Clock: clock without ext. sync signal
*/
Type type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x21, 0x02, 0x03, 0x00, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1900-01-01 01:02:03");
/*
* Reference testcase + Fault: Fault => not supported
*/
assertNull("KNXCoreTypeMapper.toType() should return null (faulty clock)", testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, (byte) 0x80, 0x00 }, DateTimeType.class));
/*
* Reference testcase + Year Field invalid => not supported
*/
assertNull("KNXCoreTypeMapper.toType() should return null (date but no year)", testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x10, 0x00 }, DateTimeType.class));
/*
* Reference testcase + Months and Day fields invalid => not supported
*/
assertNull("KNXCoreTypeMapper.toType() should return null (date but no day and month)", testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x08, 0x00 }, DateTimeType.class));
/*
* Reference testcase + Year, Months and Day fields invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x21, 0x02, 0x03, 0x18, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1970-01-01 01:02:03");
/*
* Reference testcase + Year , Months and Day fields invalid + Day of week field invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x21, 0x02, 0x03, 0x1C, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1970-01-01 01:02:03");
/*
* Reference testcase + Year, Months and Day fields invalid + Day of week field invalid
* Working day field invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x21, 0x02, 0x03, 0x3C, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1970-01-01 01:02:03");
/*
* Reference testcase + Year Field invalid + Months and Day fields invalid + Day of week field invalid
* Working day field invalid + Hour of day, Minutes and Seconds fields invalid
*/
assertNull("KNXCoreTypeMapper.toType() should return null (neither date nor time)", testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x3E, 0x00 }, DateTimeType.class));
/*
* Reference testcase + Year, Months and Day fields invalid + Day of week field invalid
* Working day field invalid + Hour of day, Minutes and Seconds fields invalid, Standard Summer Time: Time =
* UT+X+1
*/
assertNull("KNXCoreTypeMapper.toType() should return null (neither date nor time, but summertime flag)", type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x3F, 0x00 }, DateTimeType.class));
/*
* Reference testcase + day of week=Any day, Day of week field invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1900-01-01 00:00:00");
/*
* Reference testcase + Day of week field invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x04, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1900-01-01 00:00:00");
/*
* Reference testcase + day of week=Any day, Day of week field invalid, working day, working day field invalid
*/
type = testToType(dpt, new byte[] { 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, (byte) 0x60, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "1900-01-01 00:00:00");
/*
* December 31st, 2155 day of week=Any day, Day of week field invalid
*/
type = testToType(dpt, new byte[] { (byte) 0xFF, 0x0C, 0x1F, 0x17, 0x3B, 0x3B, (byte) 0x04, (byte) 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "2155-12-31 23:59:59");
/*
* December 31st, 2155, 24:00:00, day of week=Any day, Day of week field invalid
*
* TODO: this test case should test for "2155-12-31 24:00:00" since that is what the (valid) KNX bytes
* represent.
* Nevertheless, calimero is "cheating" by using the milliseconds such that "23:59:59.999" is interpreted as
* "23:59:59"
* OpenHAB's DateTimeType doesn't support milliseconds (at least not when parsing from a String), hence 24:00:00
* cannot be mapped.
*/
type = testToType(dpt, new byte[] { (byte) 0xFF, 0x0C, 0x1F, 0x18, 0x00, 0x00, (byte) 0x04, (byte) 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "2155-12-31 23:59:59");
/*
* December 31st, 2014 24:00:00, day of week=Any day, Day of week field invalid
*
* TODO: this test case should test for "2155-12-31 24:00:00" since that is what the (valid) KNX bytes
* represent.
* Nevertheless, calimero is "cheating" by using the milliseconds such that "23:59:59.999" is interpreted as
* "23:59:59"
* OpenHAB's DateTimeType doesn't support milliseconds (at least not when parsing from a String), hence 24:00:00
* cannot be mapped.
*/
type = testToType(dpt, new byte[] { (byte) 0x72, 0x0C, 0x1F, 0x18, 0x00, 0x00, (byte) 0x04, (byte) 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "2014-12-31 23:59:59");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingTime_10_001_MinutesOutOfBounds.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 10.001 DPT_TIMEOFDAY
*
* Set day to Monday, 23 hours, 60 minutes and 59 seconds
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingTime_10_001_MinutesOutOfBounds() throws KNXFormatException {
DPT dpt = DPTXlatorTime.DPT_TIMEOFDAY;
testToTypeClass(dpt, DateTimeType.class);
assertNull("KNXCoreTypeMapper.toType() should return null", testToType(dpt, new byte[] { 0x37, 60, 59 }, DateTimeType.class));
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.001 DPT_SCALING
*
* 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_001() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_SCALING;
testToTypeClass(dpt, PercentType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, PercentType.class));
Type type = testToType(dpt, new byte[] { 0x0 }, PercentType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0x80 }, PercentType.class);
testToDPTValue(dpt, type, "50");
type = testToType(dpt, new byte[] { (byte) 0xFF }, PercentType.class);
testToDPTValue(dpt, type, "100");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, PercentType.class);
testToDPTValue(dpt, type, "100");
}
Aggregations