use of org.eclipse.smarthome.core.items.Item 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.Item in project smarthome by eclipse.
the class ItemRegistryImpl method getItemsByTag.
@Override
@SuppressWarnings("unchecked")
public <T extends GenericItem> Collection<T> getItemsByTag(Class<T> typeFilter, String... tags) {
Collection<T> filteredItems = new ArrayList<T>();
Collection<Item> items = getItemsByTag(tags);
for (Item item : items) {
if (typeFilter.isInstance(item)) {
filteredItems.add((T) item);
}
}
return filteredItems;
}
use of org.eclipse.smarthome.core.items.Item 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.Item in project smarthome by eclipse.
the class ItemRegistryImpl method getItems.
@Override
public Collection<Item> getItems(String pattern) {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
Collection<Item> matchedItems = new ArrayList<Item>();
for (Item item : getItems()) {
if (item.getName().matches(regex)) {
matchedItems.add(item);
}
}
return matchedItems;
}
use of org.eclipse.smarthome.core.items.Item in project smarthome by eclipse.
the class GenericItemProvider2Test method testStableReloadOrder.
@Test
public void testStableReloadOrder() {
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()));
assertThat(itemRegistry.getAll().size(), is(10));
model = //
"Group testGroup " + //
"Number number1 (testGroup) " + //
"Number number2 (testGroup) " + //
"Number number3 (testGroup) " + //
"Number number4 (testGroup) " + //
"Number number5 (testGroup) " + //
"Number number6 (testGroup) " + //
"Number number7 \"Number Seven\" (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());
if (number == 7) {
assertEquals("Number Seven", item.getLabel());
}
}
}
Aggregations