Search in sources :

Example 6 with Type

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

the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_005.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.005
     * DPT_DECIMALFACTOR
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping8BitUnsigned_5_005() throws KNXFormatException {
    DPT dpt = DPTXlator8BitUnsigned.DPT_DECIMALFACTOR;
    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 7 with Type

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

the class KNXCoreTypeMapperTest method testTypeMappingDateTime_19_001_DST.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Date Time" KNX ID: 19.001 DPT_DATE_TIME
     * Testcase tests handling of Daylight Savings Time flag (DST).
     * Interpretation of DST is depending on default timezone, hence we're trying to test using
     * different timezones: default, New York, Berlin and Shanghai. Shanghai not having a DST.
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingDateTime_19_001_DST() throws KNXFormatException {
    DPT dpt = DPTXlatorDateTime.DPT_DATE_TIME;
    // 2014-07-31 00:00:00 DST flag set
    byte[] testDataDST = new byte[] { 0x72, 0x07, 0x1F, 0x00, 0x00, 0x00, (byte) 0x05, (byte) 0x00 };
    // 2014-07-31 00:00:00 DST flag cleared
    byte[] testDataNoDST = new byte[] { 0x72, 0x07, 0x1F, 0x00, 0x00, 0x00, (byte) 0x04, (byte) 0x00 };
    testToTypeClass(dpt, DateTimeType.class);
    Calendar c = Calendar.getInstance();
    c.set(2014, 7, 31);
    if (c.get(Calendar.DST_OFFSET) > 0) {
        // Should be null since we have a DST timezone but non-DST data: should be rejected
        assertNull(testToType(dpt, testDataNoDST, DateTimeType.class));
        Type type = testToType(dpt, testDataDST, DateTimeType.class);
        testToDPTValue(dpt, type, "2014-07-31 00:00:00");
    } else {
        // Should be null since we don't have a non-DST timezone but DST data: should be rejected
        assertNull(testToType(dpt, testDataDST, DateTimeType.class));
        Type type = testToType(dpt, testDataNoDST, DateTimeType.class);
        testToDPTValue(dpt, type, "2014-07-31 00:00:00");
    }
}
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) Calendar(java.util.Calendar) DPT(tuwien.auto.calimero.dptxlator.DPT) Test(org.junit.Test)

Example 8 with Type

use of org.openhab.core.types.Type 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 9 with Type

use of org.openhab.core.types.Type 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 10 with Type

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

the class KNXCoreTypeMapperTest method testTypeMapping2ByteFloat.

/**
     * Convenience method: testing KNXCoretypeMapper for type “Datapoint Types 2-Byte Float"
     *
     * @throws KNXFormatException
     */
private void testTypeMapping2ByteFloat(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.0");
    /*
         * Test the maximum positive value
         *
         */
    type = testToType(dpt, new byte[] { (byte) 0x7F, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "670760.96");
    type = testToType(dpt, new byte[] { (byte) 0x07, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "20.47");
    type = testToType(dpt, new byte[] { (byte) 0x87, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "-0.01");
    type = testToType(dpt, new byte[] { (byte) 0x80, (byte) 0x00 }, DecimalType.class);
    testToDPTValue(dpt, type, "-20.48");
    /*
         * Test the maximum negative value
         *
         */
    type = testToType(dpt, new byte[] { (byte) 0xF8, 0x00 }, DecimalType.class);
    testToDPTValue(dpt, type, "-671088.64");
    // Use a too long byte array expecting that additional bytes will be ignored
    type = testToType(dpt, new byte[] { (byte) 0xF8, (byte) 0x00, (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "-671088.64");
}
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)

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