use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemStateConverterImplTest method numberItemWithoutDimensionShouldConvertToDecimalType.
@Test
public void numberItemWithoutDimensionShouldConvertToDecimalType() {
Item item = new NumberItem("number");
State originalState = new QuantityType<>("12.34 °C");
State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
assertThat(convertedState, is(new DecimalType("12.34")));
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class PersistItemsJob method run.
@Override
public void run() {
synchronized (manager.persistenceServiceConfigs) {
final PersistenceService persistenceService = manager.persistenceServices.get(dbId);
final PersistenceServiceConfiguration config = manager.persistenceServiceConfigs.get(dbId);
if (persistenceService != null) {
for (SimpleItemConfiguration itemConfig : config.getConfigs()) {
if (hasStrategy(config.getDefaults(), itemConfig, strategyName)) {
for (Item item : manager.getAllItems(itemConfig)) {
long startTime = System.nanoTime();
persistenceService.store(item, itemConfig.getAlias());
logger.trace("Storing item '{}' with persistence service '{}' took {}ms", item.getName(), dbId, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
}
}
}
}
}
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class PersistenceManagerImpl method getAllItems.
/**
* Retrieves all items for which the persistence configuration applies to.
*
* @param config the persistence configuration entry
* @return all items that this configuration applies to
*/
Iterable<Item> getAllItems(SimpleItemConfiguration config) {
// first check, if we should return them all
for (Object itemCfg : config.getItems()) {
if (itemCfg instanceof SimpleAllConfig) {
return itemRegistry.getItems();
}
}
// otherwise, go through the detailed definitions
Set<Item> items = new HashSet<Item>();
for (Object itemCfg : config.getItems()) {
if (itemCfg instanceof SimpleItemConfig) {
SimpleItemConfig singleItemConfig = (SimpleItemConfig) itemCfg;
try {
Item item = itemRegistry.getItem(singleItemConfig.getItem());
items.add(item);
} catch (ItemNotFoundException e) {
logger.debug("Item '{}' does not exist.", singleItemConfig.getItem());
}
}
if (itemCfg instanceof SimpleGroupConfig) {
SimpleGroupConfig groupItemCfg = (SimpleGroupConfig) itemCfg;
String groupName = groupItemCfg.getGroup();
try {
Item gItem = itemRegistry.getItem(groupName);
if (gItem instanceof GroupItem) {
GroupItem groupItem = (GroupItem) gItem;
items.addAll(groupItem.getAllMembers());
}
} catch (ItemNotFoundException e) {
logger.debug("Item group '{}' does not exist.", groupName);
}
}
}
return items;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class QuantityTypeArithmeticGroupFunctionTest method testSumFunctionQuantityTypeIncompatibleUnits.
@Test
public void testSumFunctionQuantityTypeIncompatibleUnits() {
// we need an ordered set to guarantee the Unit of the first entry
items = new LinkedHashSet<Item>();
items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("23.54 °C")));
items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
items.add(createNumberItem("TestItem3", Pressure.class, new QuantityType<Temperature>("192.2 hPa")));
function = new QuantityTypeArithmeticGroupFunction.Sum(Temperature.class);
State state = function.calculate(items);
assertEquals(new QuantityType<Temperature>("23.54 °C"), state);
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithZonedTime.
@Test
public void getLabel_labelWithZonedTime() throws ItemNotFoundException {
String testLabel = "Label [%1$tT]";
Widget w = mock(Widget.class);
Item item = mock(Item.class);
when(w.getLabel()).thenReturn(testLabel);
when(w.getItem()).thenReturn("Item");
when(registry.getItem("Item")).thenReturn(item);
when(item.getState()).thenReturn(new DateTimeType("2011-06-01T15:30:59Z"));
String label = uiRegistry.getLabel(w);
assertEquals("Label [15:30:59]", label);
}
Aggregations