Search in sources :

Example 6 with DPT

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

the class KNXCoreTypeMapperTest method testTypeMappingColourRGB_232_600.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “3-byte RGB value" KNX ID: 232.600 DPT_Colour_RGB
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingColourRGB_232_600() throws KNXFormatException {
    DPT dpt = DPTXlatorRGB.DPT_RGB;
    testToTypeClass(dpt, HSBType.class);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, HSBType.class));
    // Use a too long byte array expecting that additional bytes will be ignored
    Type type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0 }, HSBType.class);
    testToDPTValue(dpt, type, "r:255 g:255 b:255");
    // Test max value
    type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0 }, HSBType.class);
    testToDPTValue(dpt, type, "r:255 g:255 b:255");
    // Test min value
    type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00 }, HSBType.class);
    testToDPTValue(dpt, type, "r:0 g:0 b:0");
    // Test correct interpretation of r value
    type = testToType(dpt, new byte[] { (byte) 0xff, 0x00, 0x00 }, HSBType.class);
    testToDPTValue(dpt, type, "r:255 g:0 b:0");
    // Test correct interpretation of g value
    type = testToType(dpt, new byte[] { 0x00, (byte) 0xff, 0x00 }, HSBType.class);
    testToDPTValue(dpt, type, "r:0 g:255 b:0");
    // Test correct interpretation of b value
    type = testToType(dpt, new byte[] { 0x00, 0x00, (byte) 0xff }, HSBType.class);
    testToDPTValue(dpt, type, "r:0 g:0 b: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) HSBType(org.openhab.core.library.types.HSBType) Test(org.junit.Test)

Example 7 with DPT

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

the class KNXCoreTypeMapperTest method testTypeMappingDate_11_001__ZeroMonth.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 11.001 DPT_DATE
     *
     * Test illegal month (cannot be 0) This should throw an KNXIllegalArgumentException
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingDate_11_001__ZeroMonth() throws KNXFormatException {
    DPT dpt = DPTXlatorDate.DPT_DATE;
    testToTypeClass(dpt, DateTimeType.class);
    assertNull("KNXCoreTypeMapper.toType() should return null", testToType(dpt, new byte[] { 0x01, 0x00, 0x00 }, DateTimeType.class));
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) DPT(tuwien.auto.calimero.dptxlator.DPT) Test(org.junit.Test)

Example 8 with DPT

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

the class KNXCoreTypeMapperTest method testTypeMapping4ByteFloat_14.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “4-Octet Float Value" KNX ID: 14
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping4ByteFloat_14() throws KNXFormatException {
    Locale defaultLocale = Locale.getDefault();
    Locale[] locales = { defaultLocale, Locale.ENGLISH, Locale.GERMAN };
    DPT[] dpts = { DPTXlator4ByteFloat.DPT_ACCELERATION_ANGULAR, DPTXlator4ByteFloat.DPT_ANGLE_DEG, DPTXlator4ByteFloat.DPT_ELECTRIC_CURRENT, DPTXlator4ByteFloat.DPT_ELECTRIC_POTENTIAL, DPTXlator4ByteFloat.DPT_FREQUENCY, DPTXlator4ByteFloat.DPT_POWER };
    // Iterate over the locales
    for (Locale locale : locales) {
        // Iterate over the subtypes to be tested
        for (DPT dpt : dpts) {
            Locale.setDefault(locale);
            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));
            try {
                // Use a too long byte array expecting that additional bytes will be ignored
                Type type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
                testToDPTValue(dpt, type, "340282000000000000000000000000000000000");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0");
            }
            try {
                Type type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00 }, DecimalType.class);
                testToDPTValue(dpt, type, "0.0");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0");
            }
            try {
                // Test the smallest positive value
                Type type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x01 }, DecimalType.class);
                testToDPTValue(dpt, type, "0.0000000000000000000000000000000000000000000014");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 0.0000000000000000000000000000000000000000000014");
            }
            try {
                // Test the smallest negative value
                Type type = testToType(dpt, new byte[] { (byte) 0x80, 0x00, 0x00, 0x01 }, DecimalType.class);
                testToDPTValue(dpt, type, "-0.0000000000000000000000000000000000000000000014");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting -0.0000000000000000000000000000000000000000000014");
            }
            try {
                // Test the maximum positive value
                Type type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
                testToDPTValue(dpt, type, "340282000000000000000000000000000000000");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting 340282000000000000000000000000000000000");
            }
            try {
                // Test the maximum negative value
                Type type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
                testToDPTValue(dpt, type, "-340282000000000000000000000000000000000");
            } catch (NumberFormatException nfe) {
                fail("DptId: " + dpt.getID() + ", locale: " + locale + ", NumberFormatException. Expecting -340282000000000000000000000000000000000");
            }
        }
    }
    Locale.setDefault(defaultLocale);
}
Also used : Locale(java.util.Locale) 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 9 with DPT

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

the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_004.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType()for type “8-Bit Unsigned Value" KNX ID: 5.004 DPT_PERCENT_U8
     * (previously name DPT_RelPos_Valve)
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping8BitUnsigned_5_004() throws KNXFormatException {
    DPT dpt = DPTXlator8BitUnsigned.DPT_PERCENT_U8;
    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[] { 50 }, DecimalType.class);
    testToDPTValue(dpt, type, "50");
    type = testToType(dpt, new byte[] { 100 }, DecimalType.class);
    testToDPTValue(dpt, type, "100");
    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 10 with DPT

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

the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_003.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.003 DPT_ANGLE
     *
     * 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_003() throws KNXFormatException {
    DPT dpt = DPTXlator8BitUnsigned.DPT_ANGLE;
    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, "179");
    type = testToType(dpt, new byte[] { (byte) 0x80 }, DecimalType.class);
    testToDPTValue(dpt, type, "181");
    type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "360");
    // 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, "360");
}
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)

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