Search in sources :

Example 1 with ModelGroupFunction

use of org.eclipse.smarthome.model.items.ModelGroupFunction in project smarthome by eclipse.

the class GenericItemProvider method createItemFromModelItem.

private Item createItemFromModelItem(ModelItem modelItem) {
    GenericItem item = null;
    if (modelItem instanceof ModelGroupItem) {
        ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem;
        GenericItem baseItem;
        try {
            baseItem = createItemOfType(modelGroupItem.getType(), modelGroupItem.getName());
        } catch (IllegalArgumentException e) {
            logger.debug("Error creating base item for group item '{}', item will be ignored: {}", modelGroupItem.getName(), e.getMessage());
            return null;
        }
        if (baseItem != null) {
            // if the user did not specify a function the first value of the enum in xtext (EQUAL) will be used
            ModelGroupFunction function = modelGroupItem.getFunction();
            item = applyGroupFunction(baseItem, modelGroupItem, function);
        } else {
            item = new GroupItem(modelGroupItem.getName());
        }
    } else {
        ModelNormalItem normalItem = (ModelNormalItem) modelItem;
        try {
            item = createItemOfType(normalItem.getType(), normalItem.getName());
        } catch (IllegalArgumentException e) {
            logger.debug("Error creating item '{}', item will be ignored: {}", normalItem.getName(), e.getMessage());
            return null;
        }
    }
    if (item != null) {
        String label = modelItem.getLabel();
        String format = StringUtils.substringBetween(label, "[", "]");
        if (format != null) {
            label = StringUtils.substringBefore(label, "[").trim();
            stateDescriptions.put(modelItem.getName(), new StateDescription(null, null, null, format, false, null));
        }
        item.setLabel(label);
        item.setCategory(modelItem.getIcon());
        assignTags(modelItem, item);
        return item;
    } else {
        return null;
    }
}
Also used : ModelGroupItem(org.eclipse.smarthome.model.items.ModelGroupItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) ModelGroupFunction(org.eclipse.smarthome.model.items.ModelGroupFunction) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ModelGroupItem(org.eclipse.smarthome.model.items.ModelGroupItem) ModelNormalItem(org.eclipse.smarthome.model.items.ModelNormalItem) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 2 with ModelGroupFunction

use of org.eclipse.smarthome.model.items.ModelGroupFunction in project smarthome by eclipse.

the class GenericItemProvider method applyGroupFunction.

private GroupItem applyGroupFunction(GenericItem baseItem, ModelGroupItem modelGroupItem, ModelGroupFunction function) {
    GroupFunctionDTO dto = new GroupFunctionDTO();
    dto.name = function.getName();
    dto.params = modelGroupItem.getArgs().toArray(new String[modelGroupItem.getArgs().size()]);
    GroupFunction groupFunction = ItemDTOMapper.mapFunction(baseItem, dto);
    return new GroupItem(modelGroupItem.getName(), baseItem, groupFunction);
}
Also used : GroupFunction(org.eclipse.smarthome.core.items.GroupFunction) ModelGroupFunction(org.eclipse.smarthome.model.items.ModelGroupFunction) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ModelGroupItem(org.eclipse.smarthome.model.items.ModelGroupItem) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)

Aggregations

GroupItem (org.eclipse.smarthome.core.items.GroupItem)2 ModelGroupFunction (org.eclipse.smarthome.model.items.ModelGroupFunction)2 ModelGroupItem (org.eclipse.smarthome.model.items.ModelGroupItem)2 GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 GroupFunction (org.eclipse.smarthome.core.items.GroupFunction)1 GroupFunctionDTO (org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1 ModelNormalItem (org.eclipse.smarthome.model.items.ModelNormalItem)1