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