Search in sources :

Example 11 with DPT

use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMapping2ByteUnsigned_7_004.

/**
     * KNXCoreTypeMapper tests for method typeMapper.toType() type “2-Octet Unsigned Value" KNX ID: 7.004
     * DPT_TIMEPERIOD_100
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping2ByteUnsigned_7_004() throws KNXFormatException {
    DPT dpt = DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100;
    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, "6528000");
    type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "6553500");
    // 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, "6553500");
}
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 12 with DPT

use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMappingSceneNumber_18_001.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Scene Number" KNX ID: 18.001 DPT_SCENE_CONTROL
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingSceneNumber_18_001() throws KNXFormatException {
    DPT dpt = DPTXlatorSceneControl.DPT_SCENE_CONTROL;
    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) 0xFF, 0 }, DecimalType.class);
    testToDPTValue(dpt, type, "learn 63");
    type = testToType(dpt, new byte[] { 0x00 }, DecimalType.class);
    testToDPTValue(dpt, type, "activate 0");
    type = testToType(dpt, new byte[] { 0x3F }, DecimalType.class);
    testToDPTValue(dpt, type, "activate 63");
    // Test that the second msb (reserved) are ignored
    type = testToType(dpt, new byte[] { (byte) 0xC0 }, DecimalType.class);
    testToDPTValue(dpt, type, "learn 0");
    // Test that the second msb (reserved) are ignored
    type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "learn 63");
}
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 13 with DPT

use of tuwien.auto.calimero.dptxlator.DPT 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 14 with DPT

use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMappingTime_10_001_HoursOutOfBounds.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 10.001 DPT_TIMEOFDAY
     *
     * Test case: Set day to Monday, 24 hours, 59 minutes and 59 seconds
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingTime_10_001_HoursOutOfBounds() throws KNXFormatException {
    DPT dpt = DPTXlatorTime.DPT_TIMEOFDAY;
    testToTypeClass(dpt, DateTimeType.class);
    assertNull("KNXCoreTypeMapper.toType() should return null", testToType(dpt, new byte[] { 0x38, 59, 59 }, DateTimeType.class));
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) DPT(tuwien.auto.calimero.dptxlator.DPT) Test(org.junit.Test)

Example 15 with DPT

use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.

the class KNXCoreTypeMapperTest method testTypeMappingTime_10_001.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 10.001 DPT_TIMEOFDAY
     *
     * Test case: positive tests
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingTime_10_001() throws KNXFormatException {
    DPT dpt = DPTXlatorTime.DPT_TIMEOFDAY;
    testToTypeClass(dpt, DateTimeType.class);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DateTimeType.class));
    // Use a too long byte array expecting that additional bytes will be ignored
    Type type = testToType(dpt, new byte[] { 0x20, 0x00, 0x00, (byte) 0xFF }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 00:00:00");
    /*
         * Set day to no day, 0 hours, 0 minutes and 0 seconds
         *
         */
    type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00 }, DateTimeType.class);
    String today = String.format(Locale.US, "%1$ta", Calendar.getInstance());
    testToDPTValue(dpt, type, today + ", 00:00:00");
    /*
         * Set day to Monday, 0 hours, 0 minutes and 0 seconds January 5th, 1970 was a Monday
         */
    type = testToType(dpt, new byte[] { 0x20, 0x00, 0x00 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 00:00:00");
    /*
         * * Set day to Tuesday, 0 hours, 0 minutes and 0 seconds January 6th, 1970 was a Tuesday
         */
    type = testToType(dpt, new byte[] { 0x40, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Tue, 00:00:00");
    /*
         * Set day to Wednesday, 0 hours, 0 minutes and 0 seconds January 7th, 1970 was a Wednesday
         */
    type = testToType(dpt, new byte[] { 0x60, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Wed, 00:00:00");
    /*
         * Set day to Thursday, 0 hours, 0 minutes and 0 seconds January 1st, 1970 was a Thursday
         */
    type = testToType(dpt, new byte[] { (byte) 0x80, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Thu, 00:00:00");
    /*
         * Set day to Friday, 0 hours, 0 minutes and 0 seconds January 2nd, 1970 was a Friday
         */
    type = testToType(dpt, new byte[] { (byte) 0xA0, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Fri, 00:00:00");
    /*
         * Set day to Saturday, 0 hours, 0 minutes and 0 seconds January 3rd, 1970 was a Saturday
         */
    type = testToType(dpt, new byte[] { (byte) 0xC0, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Sat, 00:00:00");
    /*
         * Set day to Sunday, 0 hours, 0 minutes and 0 seconds January 4th, 1970 was a Sunday
         */
    type = testToType(dpt, new byte[] { (byte) 0xE0, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Sun, 00:00:00");
    /*
         * Set day to Monday, 1 hour, 0 minutes and 0 seconds
         */
    type = testToType(dpt, new byte[] { 0x21, 0, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 01:00:00");
    /*
         * Set day to Monday, 0 hour, 1 minute and 0 seconds
         */
    type = testToType(dpt, new byte[] { 0x20, 1, 0 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 00:01:00");
    /*
         * Set day to Monday, 0 hour, 0 minute and 1 seconds
         */
    type = testToType(dpt, new byte[] { 0x20, 0, 1 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 00:00:01");
    /*
         * Set day to Monday, 23 hours, 59 minutes and 59 seconds
         */
    type = testToType(dpt, new byte[] { 0x37, 59, 59 }, DateTimeType.class);
    testToDPTValue(dpt, type, "Mon, 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) DPTXlatorString(tuwien.auto.calimero.dptxlator.DPTXlatorString) 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