Search in sources :

Example 16 with Type

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, "");
}
Also used : OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType) StringType(org.openhab.core.library.types.StringType) DPT(tuwien.auto.calimero.dptxlator.DPT) Test(org.junit.Test)

Example 17 with 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");
}
Also used : OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 18 with Type

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());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Example 19 with Type

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());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Example 20 with Type

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());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Aggregations

Type (org.openhab.core.types.Type)72 DecimalType (org.openhab.core.library.types.DecimalType)69 OnOffType (org.openhab.core.library.types.OnOffType)68 Test (org.junit.Test)60 SHCMessage (org.openhab.binding.smarthomatic.internal.SHCMessage)40 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)27 StringType (org.openhab.core.library.types.StringType)27 DateTimeType (org.openhab.core.library.types.DateTimeType)26 HSBType (org.openhab.core.library.types.HSBType)26 OpenClosedType (org.openhab.core.library.types.OpenClosedType)26 PercentType (org.openhab.core.library.types.PercentType)26 StopMoveType (org.openhab.core.library.types.StopMoveType)26 UpDownType (org.openhab.core.library.types.UpDownType)26 DPT (tuwien.auto.calimero.dptxlator.DPT)20 Command (org.openhab.core.types.Command)2 UnDefType (org.openhab.core.types.UnDefType)2 Calendar (java.util.Calendar)1 Locale (java.util.Locale)1 StringTokenizer (java.util.StringTokenizer)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1