use of org.openhab.core.model.items.ModelGroupItem in project openhab-core by openhab.
the class GenericItemProvider method createItemFromModelItem.
@Nullable
private Item createItemFromModelItem(ModelItem modelItem) {
Item item;
if (modelItem instanceof ModelGroupItem) {
ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem;
Item 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 instanceof ActiveItem) {
String label = modelItem.getLabel();
String format = extractFormat(label);
if (format != null) {
label = label.substring(0, label.indexOf("[")).trim();
stateDescriptionFragments.put(modelItem.getName(), StateDescriptionFragmentBuilder.create().withPattern(format).build());
}
((ActiveItem) item).setLabel(label);
((ActiveItem) item).setCategory(modelItem.getIcon());
assignTags(modelItem, (ActiveItem) item);
return item;
} else {
return null;
}
}
use of org.openhab.core.model.items.ModelGroupItem in project openhab-core by openhab.
the class GenericItemProvider method applyGroupFunction.
private GroupItem applyGroupFunction(Item baseItem, ModelGroupItem modelGroupItem, ModelGroupFunction function) {
GroupFunctionDTO dto = new GroupFunctionDTO();
dto.name = function.getName();
dto.params = modelGroupItem.getArgs().toArray(new String[0]);
GroupFunction groupFunction = ItemDTOMapper.mapFunction(baseItem, dto);
return new GroupItem(modelGroupItem.getName(), baseItem, groupFunction);
}
Aggregations