use of org.eclipse.smarthome.core.items.GenericItem 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.GenericItem in project smarthome by eclipse.
the class EnrichedItemDTOMapperTest method testFiltering.
@Test
public void testFiltering() {
GroupItem group = new GroupItem("TestGroup");
GroupItem subGroup = new GroupItem("TestSubGroup");
GenericItem switchItem = itemFactory.createItem(CoreItemFactory.SWITCH, "TestSwitch");
GenericItem numberItem = itemFactory.createItem(CoreItemFactory.NUMBER, "TestNumber");
GenericItem stringItem = itemFactory.createItem(CoreItemFactory.STRING, "TestString");
if (switchItem != null && numberItem != null && stringItem != null) {
group.addMember(subGroup);
group.addMember(switchItem);
group.addMember(numberItem);
subGroup.addMember(stringItem);
}
EnrichedGroupItemDTO dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, false, null, URI.create(""), null);
assertThat(dto.members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, null, URI.create(""), null);
assertThat(dto.members.length, is(3));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER), URI.create(""), null);
assertThat(dto.members.length, is(1));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i instanceof GroupItem, URI.create(""), null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i instanceof GroupItem, URI.create(""), null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(0));
dto = (EnrichedGroupItemDTO) EnrichedItemDTOMapper.map(group, true, i -> i.getType().equals(CoreItemFactory.NUMBER) || i.getType().equals(CoreItemFactory.STRING) || i instanceof GroupItem, URI.create(""), null);
assertThat(dto.members.length, is(2));
assertThat(((EnrichedGroupItemDTO) dto.members[0]).members.length, is(1));
}
use of org.eclipse.smarthome.core.items.GenericItem 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.GenericItem in project smarthome by eclipse.
the class WebAppServlet method addItemWithName.
private void addItemWithName(Set<GenericItem> items, String itemName) {
if (itemName != null) {
try {
Item item = renderer.getItemUIRegistry().getItem(itemName);
if (item instanceof GenericItem) {
final GenericItem gItem = (GenericItem) item;
items.add(gItem);
}
} catch (ItemNotFoundException e) {
// ignore
}
}
}
use of org.eclipse.smarthome.core.items.GenericItem in project smarthome by eclipse.
the class ItemDTOMapper method map.
/**
* Maps item DTO into item object.
*
* @param itemDTO the DTO
* @param itemFactories the item factories in order to create the items
* @return the item object
*/
@Nullable
public static ActiveItem map(ItemDTO itemDTO, Set<ItemFactory> itemFactories) {
if (itemDTO == null) {
throw new IllegalArgumentException("The argument 'itemDTO' must no be null.");
}
if (itemFactories == null) {
throw new IllegalArgumentException("The argument 'itemFactories' must no be null.");
}
GenericItem newItem = null;
if (itemDTO.type != null) {
if (itemDTO instanceof GroupItemDTO && itemDTO.type.equals(GroupItem.TYPE)) {
GroupItemDTO groupItemDTO = (GroupItemDTO) itemDTO;
GenericItem baseItem = null;
if (!StringUtils.isEmpty(groupItemDTO.groupType)) {
baseItem = createItem(groupItemDTO.groupType, itemDTO.name, itemFactories);
}
GroupFunction function = new GroupFunction.Equality();
if (groupItemDTO.function != null) {
function = mapFunction(baseItem, groupItemDTO.function);
}
newItem = new GroupItem(itemDTO.name, baseItem, function);
} else {
String itemType = itemDTO.type;
newItem = createItem(itemType, itemDTO.name, itemFactories);
}
if (newItem != null) {
if (itemDTO.label != null) {
newItem.setLabel(itemDTO.label);
}
if (itemDTO.category != null) {
newItem.setCategory(itemDTO.category);
}
if (itemDTO.groupNames != null) {
newItem.addGroupNames(itemDTO.groupNames);
}
if (itemDTO.tags != null) {
newItem.addTags(itemDTO.tags);
}
}
}
return newItem;
}
Aggregations