Search in sources :

Example 21 with DPT

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");
}
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 22 with DPT

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");
}
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 23 with DPT

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");
}
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)

Example 24 with DPT

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

Example 25 with DPT

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");
}
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) PercentType(org.openhab.core.library.types.PercentType) Test(org.junit.Test)

Aggregations

DateTimeType (org.openhab.core.library.types.DateTimeType)27 DPT (tuwien.auto.calimero.dptxlator.DPT)27 Test (org.junit.Test)26 DecimalType (org.openhab.core.library.types.DecimalType)21 HSBType (org.openhab.core.library.types.HSBType)21 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)21 OnOffType (org.openhab.core.library.types.OnOffType)21 OpenClosedType (org.openhab.core.library.types.OpenClosedType)21 PercentType (org.openhab.core.library.types.PercentType)21 StopMoveType (org.openhab.core.library.types.StopMoveType)21 StringType (org.openhab.core.library.types.StringType)21 UpDownType (org.openhab.core.library.types.UpDownType)21 Type (org.openhab.core.types.Type)20 Color (java.awt.Color)1 Calendar (java.util.Calendar)1 Locale (java.util.Locale)1 Datapoint (tuwien.auto.calimero.datapoint.Datapoint)1 DPTXlator (tuwien.auto.calimero.dptxlator.DPTXlator)1 DPTXlator1BitControlled (tuwien.auto.calimero.dptxlator.DPTXlator1BitControlled)1 DPTXlator3BitControlled (tuwien.auto.calimero.dptxlator.DPTXlator3BitControlled)1