Search in sources :

Example 81 with Item

use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.

the class GenericItemProvider2Test method testStableOrder.

@Test
public void testStableOrder() {
    assertThat(itemRegistry.getAll().size(), is(0));
    String model = // 
    "Group testGroup " + // 
    "Number number1 (testGroup) " + // 
    "Number number2 (testGroup) " + // 
    "Number number3 (testGroup) " + // 
    "Number number4 (testGroup) " + // 
    "Number number5 (testGroup) " + // 
    "Number number6 (testGroup) " + // 
    "Number number7 (testGroup) " + // 
    "Number number8 (testGroup) " + "Number number9 (testGroup) ";
    modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
    GroupItem groupItem = (GroupItem) itemRegistry.get("testGroup");
    assertNotNull(groupItem);
    int number = 0;
    Iterator<Item> it = groupItem.getMembers().iterator();
    while (it.hasNext()) {
        Item item = it.next();
        assertEquals("number" + (++number), item.getName());
    }
}
Also used : SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ByteArrayInputStream(java.io.ByteArrayInputStream) GroupItem(org.eclipse.smarthome.core.items.GroupItem) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 82 with Item

use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.

the class GenericItemProvider method getItemsFromModel.

private Collection<Item> getItemsFromModel(String modelName) {
    logger.debug("Read items from model '{}'", modelName);
    List<Item> items = new ArrayList<Item>();
    if (modelRepository != null) {
        ItemModel model = (ItemModel) modelRepository.getModel(modelName);
        if (model != null) {
            for (ModelItem modelItem : model.getItems()) {
                Item item = createItemFromModelItem(modelItem);
                if (item != null) {
                    for (String groupName : modelItem.getGroups()) {
                        ((GenericItem) item).addGroupName(groupName);
                    }
                    items.add(item);
                }
            }
        }
    }
    return items;
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem) ModelGroupItem(org.eclipse.smarthome.model.items.ModelGroupItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) ModelItem(org.eclipse.smarthome.model.items.ModelItem) ModelNormalItem(org.eclipse.smarthome.model.items.ModelNormalItem) ItemModel(org.eclipse.smarthome.model.items.ItemModel) GenericItem(org.eclipse.smarthome.core.items.GenericItem) ArrayList(java.util.ArrayList) ModelItem(org.eclipse.smarthome.model.items.ModelItem)

Example 83 with Item

use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.

the class ScriptEngineOSGiTest method testEqualsWithItemState.

@SuppressWarnings("null")
@Test
public void testEqualsWithItemState() throws ScriptExecutionException, ScriptParsingException {
    Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE);
    ((NumberItem) numberItem).setState(new QuantityType<>("20 °C"));
    assertTrue(runScript("NumberA.state == 20 [°C]"));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 84 with Item

use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.

the class ScriptEngineOSGiTest method testGreaterThanWithItemState.

@SuppressWarnings("null")
@Test
public void testGreaterThanWithItemState() throws ScriptExecutionException, ScriptParsingException {
    Item numberItem = itemRegistry.get(NUMBER_ITEM_TEMPERATURE);
    ((NumberItem) numberItem).setState(new QuantityType<>("20 °C"));
    assertTrue(runScript("NumberA.state > 20 [°F]"));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 85 with Item

use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.

the class ScriptEngineOSGiTest method testGreaterThan_Number_Number.

@Test
public void testGreaterThan_Number_Number() throws ScriptParsingException, ScriptExecutionException {
    Item numberItem = itemRegistry.get(NUMBER_ITEM_DECIMAL);
    ((NumberItem) numberItem).setState(new DecimalType(20));
    assertTrue(runScript("NumberB.state > new DecimalType(19)"));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) 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