Search in sources :

Example 6 with GenericItem

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);
        }
    }
}
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 7 with GenericItem

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));
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) EnrichedGroupItemDTO(org.eclipse.smarthome.io.rest.core.item.EnrichedGroupItemDTO) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 8 with GenericItem

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);
    }
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GenericItem(org.eclipse.smarthome.core.items.GenericItem)

Example 9 with GenericItem

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
        }
    }
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GenericItem(org.eclipse.smarthome.core.items.GenericItem) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 10 with GenericItem

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;
}
Also used : GroupFunction(org.eclipse.smarthome.core.items.GroupFunction) GenericItem(org.eclipse.smarthome.core.items.GenericItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

GenericItem (org.eclipse.smarthome.core.items.GenericItem)27 GroupItem (org.eclipse.smarthome.core.items.GroupItem)10 Item (org.eclipse.smarthome.core.items.Item)10 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)6 Test (org.junit.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Path (javax.ws.rs.Path)2 ActiveItem (org.eclipse.smarthome.core.items.ActiveItem)2 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)2 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)2 ModelGroupItem (org.eclipse.smarthome.model.items.ModelGroupItem)2 ModelNormalItem (org.eclipse.smarthome.model.items.ModelNormalItem)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1