Search in sources :

Example 66 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMapping2ByteUnsigned.

/**
     * Convenience method: testing KNXCoretypeMapper for type “Datapoint Types 2-Byte Float"
     *
     * @throws KNXFormatException
     */
private void testTypeMapping2ByteUnsigned(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");
    type = testToType(dpt, new byte[] { (byte) 0xFF, 0x00 }, DecimalType.class);
    testToDPTValue(dpt, type, "65280");
    type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "65535");
    // 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, "65535");
}
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 67 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMapping2ByteUnsigned_7_003.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “2-Octet Unsigned Value" KNX ID: 7.003
     * DPT_TIMEPERIOD_10
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping2ByteUnsigned_7_003() throws KNXFormatException {
    DPT dpt = DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_10;
    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, "652800");
    type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "655350");
    // 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, "655350");
}
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) DPT(tuwien.auto.calimero.dptxlator.DPT) DecimalType(org.openhab.core.library.types.DecimalType) Test(org.junit.Test)

Example 68 with Type

use of org.openhab.core.types.Type 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");
}
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) DPT(tuwien.auto.calimero.dptxlator.DPT) DecimalType(org.openhab.core.library.types.DecimalType) Test(org.junit.Test)

Example 69 with Type

use of org.openhab.core.types.Type 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");
}
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) DPT(tuwien.auto.calimero.dptxlator.DPT) DecimalType(org.openhab.core.library.types.DecimalType) Test(org.junit.Test)

Example 70 with Type

use of org.openhab.core.types.Type 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");
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) 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) DPT(tuwien.auto.calimero.dptxlator.DPT) 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