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, "");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping4ByteSigned.
/**
* Convenience method: testing KNXCoretypeMapper for type “Datapoint Types 4-Byte Signed"
*
* @throws KNXFormatException
*/
private void testTypeMapping4ByteSigned(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));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "2147483647");
type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "-1");
type = testToType(dpt, new byte[] { (byte) 0x80, 0x00, 0x00, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "-2147483648");
type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "2147483647");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class TestSHCMessage method testWeatherTempHumMinMax2.
/**
* test data is: weather temperature & humidity: 0 (0x000) temperatur: 32767
* (0x7FFF)
*/
@Test
public void testWeatherTempHumMinMax2() {
String message = " PKT:SID=10;PC=17531;MT=8;MGID=10;MID=2;MD=001FFFC00000;785c34de";
SHCMessage shcMessage = new SHCMessage(message, packet);
List<Type> values = shcMessage.getData().getOpenHABTypes();
assertEquals(0, ((DecimalType) values.get(0)).intValue());
assertEquals(32767, ((DecimalType) values.get(1)).intValue());
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class TestSHCMessage method testWeatherTempMax.
/**
* test data is: weather temperature: 32767 = 0x7FFF (max)
*/
@Test
public void testWeatherTempMax() {
String message = " PKT:SID=11;PC=68026;MT=8;MGID=10;MID=1;MD=7FFF00000000;dbd5c390";
SHCMessage shcMessage = new SHCMessage(message, packet);
List<Type> values = shcMessage.getData().getOpenHABTypes();
assertEquals(32767, ((DecimalType) values.get(0)).intValue());
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class TestSHCMessage method testDimmerAnimationTyp.
/**
* test data is: Dimmer Animation: 13 (typ)
*/
@Test
public void testDimmerAnimationTyp() {
String message = " PKT:SID=13;PC=534;MT=10;MGID=60;MID=2;MD=40f4006000000000000000000000000000;5817ba52";
SHCMessage shcMessage = new SHCMessage(message, packet);
List<Type> values = shcMessage.getData().getOpenHABTypes();
assertEquals("AnimationMode", 1, ((DecimalType) values.get(0)).intValue());
assertEquals("TimeoutSec", 976, ((DecimalType) values.get(1)).intValue());
assertEquals("StartBrightness", 0, ((DecimalType) values.get(2)).intValue());
assertEquals("EndBrightness", 96, ((DecimalType) values.get(3)).intValue());
}
Aggregations