Search in sources :

Example 26 with GroupItem

use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.

the class ItemDTOMapper method fillProperties.

private static void fillProperties(ItemDTO itemDTO, Item item) {
    if (item instanceof GroupItem) {
        GroupItem groupItem = (GroupItem) item;
        GroupItemDTO groupItemDTO = (GroupItemDTO) itemDTO;
        if (groupItem.getBaseItem() != null) {
            groupItemDTO.groupType = groupItem.getBaseItem().getType();
            groupItemDTO.function = mapFunction(groupItem.getFunction());
        }
    }
    itemDTO.name = item.getName();
    itemDTO.type = item.getType();
    itemDTO.label = item.getLabel();
    itemDTO.tags = item.getTags();
    itemDTO.category = item.getCategory();
    itemDTO.groupNames = item.getGroupNames();
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem)

Example 27 with GroupItem

use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.

the class AbstractRuleBasedInterpreter method addItem.

private void addItem(Locale locale, HashMap<Item, ArrayList<HashSet<String>>> target, HashSet<String> tokens, Item item) {
    HashSet<String> nt = new HashSet<String>(tokens);
    nt.addAll(tokenize(locale, item.getLabel()));
    ArrayList<HashSet<String>> list = target.get(item);
    if (list == null) {
        target.put(item, list = new ArrayList<HashSet<String>>());
    }
    list.add(nt);
    if (item instanceof GroupItem) {
        for (Item member : ((GroupItem) item).getMembers()) {
            addItem(locale, target, nt, member);
        }
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ArrayList(java.util.ArrayList) GroupItem(org.eclipse.smarthome.core.items.GroupItem) HashSet(java.util.HashSet)

Example 28 with GroupItem

use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.

the class ItemResource method removeMember.

@DELETE
@RolesAllowed({ Role.ADMIN })
@Path("/{itemName: [a-zA-Z_0-9]*}/members/{memberItemName: [a-zA-Z_0-9]*}")
@ApiOperation(value = "Removes an existing member from a group item.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Item or member item not found or item is not of type group item."), @ApiResponse(code = 405, message = "Member item is not editable.") })
public Response removeMember(@PathParam("itemName") @ApiParam(value = "item name", required = true) String itemName, @PathParam("memberItemName") @ApiParam(value = "member item name", required = true) String memberItemName) {
    try {
        Item item = itemRegistry.getItem(itemName);
        if (!(item instanceof GroupItem)) {
            return Response.status(Status.NOT_FOUND).build();
        }
        GroupItem groupItem = (GroupItem) item;
        Item memberItem = itemRegistry.getItem(memberItemName);
        if (!(memberItem instanceof GenericItem)) {
            return Response.status(Status.NOT_FOUND).build();
        }
        if (managedItemProvider.get(memberItemName) == null) {
            return Response.status(Status.METHOD_NOT_ALLOWED).build();
        }
        GenericItem genericMemberItem = (GenericItem) memberItem;
        genericMemberItem.removeGroupName(groupItem.getName());
        managedItemProvider.update(genericMemberItem);
        return Response.ok(null, MediaType.TEXT_PLAIN).build();
    } catch (ItemNotFoundException e) {
        return Response.status(Status.NOT_FOUND).build();
    }
}
Also used : ActiveItem(org.eclipse.smarthome.core.items.ActiveItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) 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) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 29 with GroupItem

use of org.eclipse.smarthome.core.items.GroupItem in project smarthome by eclipse.

the class ChartRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Chart chart = (Chart) w;
    try {
        String itemParam = null;
        Item item = itemUIRegistry.getItem(chart.getItem());
        if (item instanceof GroupItem) {
            itemParam = "groups=" + chart.getItem();
        } else {
            itemParam = "items=" + chart.getItem();
        }
        String chartUrl = "/chart?" + itemParam + "&period=" + chart.getPeriod();
        if (chart.getService() != null) {
            chartUrl += "&service=" + chart.getService();
        }
        // if legend parameter is given, add corresponding GET parameter
        if (chart.getLegend() != null) {
            if (chart.getLegend()) {
                chartUrl += "&legend=true";
            } else {
                chartUrl += "&legend=false";
            }
        }
        // add theme GET parameter
        String chartTheme = null;
        switch(config.getTheme()) {
            case WebAppConfig.THEME_NAME_DEFAULT:
                chartTheme = "bright";
                break;
            case WebAppConfig.THEME_NAME_DARK:
                chartTheme = "dark";
                break;
        }
        if (chartTheme != null) {
            chartUrl += "&theme=" + chartTheme;
        }
        String url;
        boolean ignoreRefresh;
        if (!itemUIRegistry.getVisiblity(w)) {
            url = URL_NONE_ICON;
            ignoreRefresh = true;
        } else {
            // add timestamp to circumvent browser cache
            url = chartUrl + "&t=" + (new Date()).getTime();
            ignoreRefresh = false;
        }
        String snippet = getSnippet("chart");
        snippet = preprocessSnippet(snippet, w);
        if (chart.getRefresh() > 0) {
            snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(chart.getRefresh()));
        } else {
            snippet = StringUtils.replace(snippet, "%update_interval%", "0");
        }
        snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
        snippet = StringUtils.replace(snippet, "%proxied_url%", chartUrl);
        snippet = StringUtils.replace(snippet, "%valid_url%", "true");
        snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
        snippet = StringUtils.replace(snippet, "%url%", url);
        sb.append(snippet);
    } catch (ItemNotFoundException e) {
        logger.warn("Chart cannot be rendered as item '{}' does not exist.", chart.getItem());
    }
    return null;
}
Also used : Item(org.eclipse.smarthome.core.items.Item) GroupItem(org.eclipse.smarthome.core.items.GroupItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) Chart(org.eclipse.smarthome.model.sitemap.Chart) Date(java.util.Date) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Aggregations

GroupItem (org.eclipse.smarthome.core.items.GroupItem)29 Item (org.eclipse.smarthome.core.items.Item)18 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)13 GenericItem (org.eclipse.smarthome.core.items.GenericItem)12 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)11 Test (org.junit.Test)8 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)7 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)5 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 GroupFunction (org.eclipse.smarthome.core.items.GroupFunction)3 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)3 ModelGroupFunction (org.eclipse.smarthome.model.items.ModelGroupFunction)3 ModelGroupItem (org.eclipse.smarthome.model.items.ModelGroupItem)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2