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;
}
}
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);
}
Aggregations