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);
}
}
}
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.");
}
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);
}
}
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);
}
}
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);
}
}
Aggregations