use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testProcessBindingConfig_FileUsage01.
/*** END of "DirFiles" tests ***/
/*
* "DirUsage" tests
*/
@Test
public /* Verify a simple dir usage configuration: "DirUsage:60000:/temp" */
void testProcessBindingConfig_FileUsage01() throws BindingConfigParseException {
NumberItem testItem = new NumberItem("DirUsage01");
String simpleConfig = "DirUsage:60000:/temp";
provider.processBindingConfiguration("systeminfo", testItem, simpleConfig);
Assert.assertNull(provider.getCommandType(null));
Assert.assertNull(provider.getCommandType(""));
Assert.assertEquals("DirUsage", provider.getCommandType("DirUsage01").toString());
Assert.assertNull(provider.getItemType(null));
Assert.assertNull(provider.getItemType(""));
Assert.assertNull(provider.getItemType("DirUsage01"));
Assert.assertEquals(0, provider.getRefreshInterval(null));
Assert.assertEquals(0, provider.getRefreshInterval(""));
Assert.assertEquals(60000, provider.getRefreshInterval("DirUsage01"));
Assert.assertNull(provider.getTarget(null));
Assert.assertNull(provider.getTarget(""));
Assert.assertEquals("/temp", provider.getTarget("DirUsage01"));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class InfluxDBPersistenceService method objectToState.
/**
* Converts a value to a {@link State} which is suitable for the given {@link Item}. This is
* needed for querying a {@link HistoricState}.
*
* @param value to be converted to a {@link State}
* @param itemName name of the {@link Item} to get the {@link State} for
* @return the state of the item represented by the itemName parameter,
* else the string value of the Object parameter
*/
private State objectToState(Object value, String itemName) {
String valueStr = String.valueOf(value);
if (itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof NumberItem) {
return new DecimalType(valueStr);
} else if (item instanceof ColorItem) {
return new HSBType(valueStr);
} else if (item instanceof DimmerItem) {
return new PercentType(valueStr);
} else if (item instanceof SwitchItem) {
return string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF) ? OnOffType.OFF : OnOffType.ON;
} else if (item instanceof ContactItem) {
return (string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF)) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
} else if (item instanceof RollershutterItem) {
return new PercentType(valueStr);
} else if (item instanceof DateTimeItem) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(new BigDecimal(valueStr).longValue());
return new DateTimeType(calendar);
} else {
return new StringType(valueStr);
}
} catch (ItemNotFoundException e) {
logger.warn("Could not find item '{}' in registry", itemName);
}
}
// just return a StringType as a fallback
return new StringType(valueStr);
}
use of org.openhab.core.library.items.NumberItem 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.NumberItem in project openhab1-addons by openhab.
the class AbstractDynamoDBItemSerializationTest method testDecimalTypeWithNumberItem.
@Test
public void testDecimalTypeWithNumberItem() throws IOException {
DynamoDBItem<?> dbitem = testStateGeneric(new DecimalType(3.2), new BigDecimal(3.2));
testAsHistoricGeneric(dbitem, new NumberItem("foo"), new DecimalType(3.2));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class BaseIntegrationTest method initService.
@BeforeClass
public static void initService() throws InterruptedException {
items.put("dimmer", new DimmerItem("dimmer"));
items.put("number", new NumberItem("number"));
items.put("string", new StringItem("string"));
items.put("switch", new SwitchItem("switch"));
items.put("contact", new ContactItem("contact"));
items.put("color", new ColorItem("color"));
items.put("rollershutter", new RollershutterItem("rollershutter"));
items.put("datetime", new DateTimeItem("datetime"));
items.put("call", new CallItem("call"));
items.put("location", new LocationItem("location"));
service = new DynamoDBPersistenceService();
service.setItemRegistry(new ItemRegistry() {
@Override
public void removeItemRegistryChangeListener(ItemRegistryChangeListener listener) {
throw new NotImplementedException();
}
@Override
public boolean isValidItemName(String itemName) {
throw new NotImplementedException();
}
@Override
public Collection<Item> getItems(String pattern) {
throw new NotImplementedException();
}
@Override
public Collection<Item> getItems() {
throw new NotImplementedException();
}
@Override
public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
throw new NotImplementedException();
}
@Override
public Item getItem(String name) throws ItemNotFoundException {
Item item = items.get(name);
if (item == null) {
throw new ItemNotFoundException(name);
}
return item;
}
@Override
public void addItemRegistryChangeListener(ItemRegistryChangeListener listener) {
throw new NotImplementedException();
}
});
HashMap<String, Object> config = new HashMap<>();
config.put("region", System.getProperty("DYNAMODBTEST_REGION"));
config.put("accessKey", System.getProperty("DYNAMODBTEST_ACCESS"));
config.put("secretKey", System.getProperty("DYNAMODBTEST_SECRET"));
config.put("tablePrefix", "dynamodb-integration-tests-");
for (Entry<String, Object> entry : config.entrySet()) {
if (entry.getValue() == null) {
logger.warn(String.format("Expecting %s to have value for integration tests. Integration tests will be skipped", entry.getKey()));
service = null;
return;
}
}
service.activate(null, config);
// Clear data
for (String table : new String[] { "dynamodb-integration-tests-bigdecimal", "dynamodb-integration-tests-string" }) {
try {
service.getDb().getDynamoClient().deleteTable(table);
service.getDb().getDynamoDB().getTable(table).waitForDelete();
} catch (ResourceNotFoundException e) {
}
}
}
Aggregations