use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_005.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.005
* DPT_DECIMALFACTOR
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitUnsigned_5_005() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_DECIMALFACTOR;
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 org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingDateTime_19_001_DST.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Date Time" KNX ID: 19.001 DPT_DATE_TIME
* Testcase tests handling of Daylight Savings Time flag (DST).
* Interpretation of DST is depending on default timezone, hence we're trying to test using
* different timezones: default, New York, Berlin and Shanghai. Shanghai not having a DST.
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingDateTime_19_001_DST() throws KNXFormatException {
DPT dpt = DPTXlatorDateTime.DPT_DATE_TIME;
// 2014-07-31 00:00:00 DST flag set
byte[] testDataDST = new byte[] { 0x72, 0x07, 0x1F, 0x00, 0x00, 0x00, (byte) 0x05, (byte) 0x00 };
// 2014-07-31 00:00:00 DST flag cleared
byte[] testDataNoDST = new byte[] { 0x72, 0x07, 0x1F, 0x00, 0x00, 0x00, (byte) 0x04, (byte) 0x00 };
testToTypeClass(dpt, DateTimeType.class);
Calendar c = Calendar.getInstance();
c.set(2014, 7, 31);
if (c.get(Calendar.DST_OFFSET) > 0) {
// Should be null since we have a DST timezone but non-DST data: should be rejected
assertNull(testToType(dpt, testDataNoDST, DateTimeType.class));
Type type = testToType(dpt, testDataDST, DateTimeType.class);
testToDPTValue(dpt, type, "2014-07-31 00:00:00");
} else {
// Should be null since we don't have a non-DST timezone but DST data: should be rejected
assertNull(testToType(dpt, testDataDST, DateTimeType.class));
Type type = testToType(dpt, testDataNoDST, DateTimeType.class);
testToDPTValue(dpt, type, "2014-07-31 00:00:00");
}
}
use of org.openhab.core.types.Type 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 org.openhab.core.types.Type 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 org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping2ByteFloat.
/**
* Convenience method: testing KNXCoretypeMapper for type “Datapoint Types 2-Byte Float"
*
* @throws KNXFormatException
*/
private void testTypeMapping2ByteFloat(DPT dpt) throws KNXFormatException {
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.0");
/*
* Test the maximum positive value
*
*/
type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "670760.96");
type = testToType(dpt, new byte[] { (byte) 0x07, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "20.47");
type = testToType(dpt, new byte[] { (byte) 0x87, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "-0.01");
type = testToType(dpt, new byte[] { (byte) 0x80, (byte) 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "-20.48");
/*
* Test the maximum negative value
*
*/
type = testToType(dpt, new byte[] { (byte) 0xF8, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "-671088.64");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xF8, (byte) 0x00, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "-671088.64");
}
Aggregations