Search in sources :

Example 66 with Item

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")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 67 with Item

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));
                    }
                }
            }
        }
    }
}
Also used : PersistenceService(org.eclipse.smarthome.core.persistence.PersistenceService) Item(org.eclipse.smarthome.core.items.Item) SimpleItemConfiguration(org.eclipse.smarthome.core.persistence.SimpleItemConfiguration) PersistenceServiceConfiguration(org.eclipse.smarthome.core.persistence.PersistenceServiceConfiguration)

Example 68 with Item

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;
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem) HistoricItem(org.eclipse.smarthome.core.persistence.HistoricItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) SimpleGroupConfig(org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig) SimpleAllConfig(org.eclipse.smarthome.core.persistence.config.SimpleAllConfig) SimpleItemConfig(org.eclipse.smarthome.core.persistence.config.SimpleItemConfig) GroupItem(org.eclipse.smarthome.core.items.GroupItem) HashSet(java.util.HashSet) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 69 with Item

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);
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) Temperature(javax.measure.quantity.Temperature) State(org.eclipse.smarthome.core.types.State) Pressure(javax.measure.quantity.Pressure) Test(org.junit.Test)

Example 70 with Item

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);
}
Also used : ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Widget(org.eclipse.smarthome.model.sitemap.Widget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Item (org.eclipse.smarthome.core.items.Item)111 GroupItem (org.eclipse.smarthome.core.items.GroupItem)42 GenericItem (org.eclipse.smarthome.core.items.GenericItem)39 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)37 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)35 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)31 State (org.eclipse.smarthome.core.types.State)26 Test (org.junit.Test)26 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)14 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)14 StringItem (org.eclipse.smarthome.core.library.items.StringItem)14 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)13 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)12 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)10 IntentInterpretation (org.openhab.ui.habot.nlp.IntentInterpretation)10 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)9 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 Thing (org.eclipse.smarthome.core.thing.Thing)9 Set (java.util.Set)8 Widget (org.eclipse.smarthome.model.sitemap.Widget)8