Search in sources :

Example 21 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class JdbcBaseDAO method getState.

/*****************
     * H E L P E R S *
     *****************/
protected State getState(Item item, Object v) {
    String clazz = v.getClass().getSimpleName();
    logger.debug("JDBC::ItemResultHandler::handleResult getState value = '{}', getClass = '{}', clazz = '{}'", v.toString(), v.getClass(), clazz);
    if (item instanceof NumberItem) {
        String it = getSqlTypes().get("NUMBERITEM");
        if (it.toUpperCase().contains("DOUBLE")) {
            return new DecimalType(((Number) v).doubleValue());
        } else if (it.toUpperCase().contains("DECIMAL") || it.toUpperCase().contains("NUMERIC")) {
            return new DecimalType((BigDecimal) v);
        } else if (it.toUpperCase().contains("INT")) {
            return new DecimalType(((Integer) v).intValue());
        }
        return DecimalType.valueOf(((String) v).toString());
    } else if (item instanceof ColorItem) {
        return HSBType.valueOf(((String) v).toString());
    } else if (item instanceof DimmerItem) {
        return new PercentType(objectAsInteger(v));
    } else if (item instanceof SwitchItem) {
        return OnOffType.valueOf(((String) v).toString().trim());
    } else if (item instanceof ContactItem) {
        return OpenClosedType.valueOf(((String) v).toString().trim());
    } else if (item instanceof RollershutterItem) {
        return new PercentType(objectAsInteger(v));
    } else if (item instanceof DateTimeItem) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(objectAsLong(v));
        return new DateTimeType(calendar);
    } else if (item instanceof StringItem) {
        return StringType.valueOf(((String) v).toString());
    } else {
        // Call, Location, String
        return StringType.valueOf(((String) v).toString());
    }
}
Also used : ContactItem(org.openhab.core.library.items.ContactItem) Calendar(java.util.Calendar) ColorItem(org.openhab.core.library.items.ColorItem) PercentType(org.openhab.core.library.types.PercentType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) BigDecimal(java.math.BigDecimal) NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 22 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class StringItemIntegrationTest method storeData.

@BeforeClass
public static void storeData() throws InterruptedException {
    StringItem item = (StringItem) items.get(name);
    item.setState(state1);
    beforeStore = new Date();
    Thread.sleep(10);
    service.store(item);
    afterStore1 = new Date();
    Thread.sleep(10);
    item.setState(state2);
    service.store(item);
    Thread.sleep(10);
    afterStore2 = new Date();
    logger.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore), AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
}
Also used : StringItem(org.openhab.core.library.items.StringItem) Date(java.util.Date) BeforeClass(org.junit.BeforeClass)

Example 23 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeWithStringItem.

@Test
public void testDateTimeTypeWithStringItem() throws IOException {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.set(2016, Calendar.MAY, 1, 13, 46, 0);
    calendar.set(Calendar.MILLISECOND, 50);
    DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-05-01T13:46:00.050Z");
    testAsHistoricGeneric(dbitem, new StringItem("foo"), new StringType("2016-05-01T13:46:00.050Z"));
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) StringItem(org.openhab.core.library.items.StringItem) Test(org.junit.Test)

Example 24 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class AbstractDynamoDBItemSerializationTest method testDateTimeTypeLocalWithStringItem.

@Test
public void testDateTimeTypeLocalWithStringItem() throws IOException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("GMT+03:00"));
    // GMT: Sun, 17 Jul 2016 16:38:07.050 GMT
    calendar.setTimeInMillis(1468773487050L);
    DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-07-17T16:38:07.050Z");
    testAsHistoricGeneric(dbitem, new StringItem("foo"), new StringType("2016-07-17T16:38:07.050Z"));
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) StringItem(org.openhab.core.library.items.StringItem) Test(org.junit.Test)

Example 25 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class AbstractDynamoDBItemSerializationTest method testStringTypeWithStringItem.

@Test
public void testStringTypeWithStringItem() throws IOException {
    DynamoDBItem<?> dbitem = testStateGeneric(new StringType("foo bar"), "foo bar");
    testAsHistoricGeneric(dbitem, new StringItem("foo"), new StringType("foo bar"));
}
Also used : StringType(org.openhab.core.library.types.StringType) StringItem(org.openhab.core.library.items.StringItem) Test(org.junit.Test)

Aggregations

StringItem (org.openhab.core.library.items.StringItem)27 NumberItem (org.openhab.core.library.items.NumberItem)16 StringType (org.openhab.core.library.types.StringType)16 DecimalType (org.openhab.core.library.types.DecimalType)14 SwitchItem (org.openhab.core.library.items.SwitchItem)12 DimmerItem (org.openhab.core.library.items.DimmerItem)8 DateTimeType (org.openhab.core.library.types.DateTimeType)8 Test (org.junit.Test)7 ContactItem (org.openhab.core.library.items.ContactItem)7 Calendar (java.util.Calendar)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)5 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 PercentType (org.openhab.core.library.types.PercentType)5 BigDecimal (java.math.BigDecimal)4 ColorItem (org.openhab.core.library.items.ColorItem)4 Date (java.util.Date)3 Item (org.openhab.core.items.Item)3 State (org.openhab.core.types.State)3 LinkedList (java.util.LinkedList)2 JSONException (org.json.JSONException)2