use of org.eclipse.smarthome.core.items.ItemNotUniqueException 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.ItemNotUniqueException 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);
}
}
use of org.eclipse.smarthome.core.items.ItemNotUniqueException in project smarthome by eclipse.
the class VoiceConsoleCommandExtension method say.
private void say(String[] args, Console console) {
StringBuilder msg = new StringBuilder();
for (String word : args) {
if (word.startsWith("%") && word.endsWith("%") && word.length() > 2) {
String itemName = word.substring(1, word.length() - 1);
try {
Item item = this.itemRegistry.getItemByPattern(itemName);
msg.append(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 {
msg.append(word);
}
msg.append(" ");
}
voiceManager.say(msg.toString());
}
use of org.eclipse.smarthome.core.items.ItemNotUniqueException in project smarthome by eclipse.
the class ItemRegistryImpl method getItemByPattern.
@Override
public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
Collection<Item> items = getItems(name);
if (items.isEmpty()) {
throw new ItemNotFoundException(name);
}
if (items.size() > 1) {
throw new ItemNotUniqueException(name, items);
}
Item item = items.iterator().next();
if (item == null) {
throw new ItemNotFoundException(name);
} else {
return item;
}
}
use of org.eclipse.smarthome.core.items.ItemNotUniqueException in project smarthome by eclipse.
the class SendConsoleCommandExtension 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 commandName = args[1];
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName);
if (command != null) {
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
console.println("Command has been sent successfully.");
} else {
console.println("Error: Command '" + commandName + "' is not valid for item '" + itemName + "'");
console.println("Valid command types are:");
for (Class<? extends Command> acceptedType : item.getAcceptedCommandTypes()) {
console.print(" " + acceptedType.getSimpleName());
if (acceptedType.isEnum()) {
console.print(": ");
for (Object e : acceptedType.getEnumConstants()) {
console.print(e + " ");
}
}
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