Search in sources :

Example 11 with Item

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

the class PageChangeListener method updateItemsAndWidgets.

private void updateItemsAndWidgets(EList<Widget> widgets) {
    if (this.widgets != null) {
        // cleanup statechange listeners in case widgets were removed
        items = getAllItems(this.widgets);
        for (Item item : items) {
            if (item instanceof GenericItem) {
                ((GenericItem) item).removeStateChangeListener(this);
            }
        }
    }
    this.widgets = widgets;
    items = getAllItems(widgets);
    for (Item item : items) {
        if (item instanceof GenericItem) {
            ((GenericItem) item).addStateChangeListener(this);
        }
    }
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem)

Example 12 with Item

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

the class ItemConsoleCommandExtension method removeItems.

private void removeItems(Console console, Collection<Item> items) {
    int count = items.size();
    for (Item item : items) {
        itemRegistry.remove(item.getName());
    }
    console.println(count + " item(s) removed successfully.");
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item)

Example 13 with Item

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

the class ItemConsoleCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length > 0) {
        String subCommand = args[0];
        switch(subCommand) {
            case SUBCMD_LIST:
                listItems(console, (args.length < 2) ? "*" : args[1]);
                break;
            case SUBCMD_CLEAR:
                removeItems(console, itemRegistry.getAll());
                break;
            case SUBCMD_REMOVE:
                if (args.length > 1) {
                    String name = args[1];
                    Item item = itemRegistry.get(name);
                    removeItems(console, Collections.singleton(item));
                } else {
                    console.println("Specify the name of the item to remove: " + this.getCommand() + " " + SUBCMD_REMOVE + " <itemName>");
                }
                break;
            case SUBCMD_ADDTAG:
                if (args.length > 2) {
                    Item item = itemRegistry.get(args[1]);
                    if (item instanceof GenericItem) {
                        GenericItem gItem = (GenericItem) item;
                        handleTags(gItem::addTag, args[2], gItem, console);
                    }
                } else {
                    console.println("Specify the name of the item and the tag: " + this.getCommand() + " " + SUBCMD_ADDTAG + " <itemName> <tag>");
                }
                break;
            case SUBCMD_RMTAG:
                if (args.length > 2) {
                    Item item = itemRegistry.get(args[1]);
                    if (item instanceof GenericItem) {
                        GenericItem gItem = (GenericItem) item;
                        handleTags(gItem::removeTag, args[2], gItem, console);
                    }
                } else {
                    console.println("Specify the name of the item and the tag: " + this.getCommand() + " " + SUBCMD_RMTAG + " <itemName> <tag>");
                }
                break;
            default:
                console.println("Unknown command '" + subCommand + "'");
                printUsage(console);
                break;
        }
    } else {
        printUsage(console);
    }
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GenericItem(org.eclipse.smarthome.core.items.GenericItem)

Example 14 with Item

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

the class StatusConsoleCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length > 0) {
        String itemName = args[0];
        try {
            Item item = this.itemRegistry.getItemByPattern(itemName);
            console.println(item.getState().toString());
        } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
        } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for (Item item : e.getMatchingItems()) {
                console.print(item.getName() + " ");
            }
        }
    } else {
        printUsage(console);
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) ItemNotUniqueException(org.eclipse.smarthome.core.items.ItemNotUniqueException) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 15 with Item

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

the class UpdateConsoleCommandExtension method execute.

@Override
public void execute(String[] args, Console console) {
    if (args.length > 0) {
        String itemName = args[0];
        try {
            Item item = this.itemRegistry.getItemByPattern(itemName);
            if (args.length > 1) {
                String stateName = args[1];
                State state = TypeParser.parseState(item.getAcceptedDataTypes(), stateName);
                if (state != null) {
                    eventPublisher.post(ItemEventFactory.createStateEvent(item.getName(), state));
                    console.println("Update has been sent successfully.");
                } else {
                    console.println("Error: State '" + stateName + "' is not valid for item '" + itemName + "'");
                    console.print("Valid data types are: ( ");
                    for (Class<? extends State> acceptedType : item.getAcceptedDataTypes()) {
                        console.print(acceptedType.getSimpleName() + " ");
                    }
                    console.println(")");
                }
            } else {
                printUsage(console);
            }
        } catch (ItemNotFoundException e) {
            console.println("Error: Item '" + itemName + "' does not exist.");
        } catch (ItemNotUniqueException e) {
            console.print("Error: Multiple items match this pattern: ");
            for (Item item : e.getMatchingItems()) {
                console.print(item.getName() + " ");
            }
        }
    } else {
        printUsage(console);
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) State(org.eclipse.smarthome.core.types.State) ItemNotUniqueException(org.eclipse.smarthome.core.items.ItemNotUniqueException) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

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