use of org.eclipse.smarthome.model.sitemap.ColorArray in project smarthome by eclipse.
the class SitemapResourceTest method initSitemapWidgets.
private EList<Widget> initSitemapWidgets() {
// Initialize a sitemap containing 2 widgets linked to the same number item,
// one slider and one switch
Widget w1 = mock(Widget.class);
EClass sliderEClass = mock(EClass.class);
when(sliderEClass.getName()).thenReturn("slider");
when(sliderEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Slider");
when(w1.eClass()).thenReturn(sliderEClass);
when(w1.getLabel()).thenReturn(WIDGET1_LABEL);
when(w1.getItem()).thenReturn(ITEM_NAME);
// add visibility rules to the mock widget:
VisibilityRule visibilityRule = mock(VisibilityRule.class);
when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
visibilityRules.add(visibilityRule);
when(w1.getVisibility()).thenReturn(visibilityRules);
// add label color conditions to the item:
ColorArray labelColor = mock(ColorArray.class);
when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
EList<ColorArray> labelColors = new BasicEList<>();
labelColors.add(labelColor);
when(w1.getLabelColor()).thenReturn(labelColors);
// add value color conditions to the item:
ColorArray valueColor = mock(ColorArray.class);
when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
EList<ColorArray> valueColors = new BasicEList<>();
valueColors.add(valueColor);
when(w1.getValueColor()).thenReturn(valueColors);
visibilityRules = new BasicEList<>();
labelColors = new BasicEList<>();
valueColors = new BasicEList<>();
Widget w2 = mock(Widget.class);
EClass switchEClass = mock(EClass.class);
when(switchEClass.getName()).thenReturn("switch");
when(switchEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Switch");
when(w2.eClass()).thenReturn(switchEClass);
when(w2.getLabel()).thenReturn(WIDGET2_LABEL);
when(w2.getItem()).thenReturn(ITEM_NAME);
when(w2.getVisibility()).thenReturn(visibilityRules);
when(w2.getLabelColor()).thenReturn(labelColors);
when(w2.getValueColor()).thenReturn(valueColors);
BasicEList<Widget> widgets = new BasicEList<>(2);
widgets.add(w1);
widgets.add(w2);
return widgets;
}
use of org.eclipse.smarthome.model.sitemap.ColorArray in project smarthome by eclipse.
the class ItemUIRegistryImpl method processColorDefinition.
private String processColorDefinition(State state, List<ColorArray> colorList) {
// Sanity check
if (colorList == null) {
return null;
}
if (colorList.size() == 0) {
return null;
}
String colorString = null;
// static colour
if (colorList.size() == 1 && colorList.get(0).getState() == null) {
colorString = colorList.get(0).getArg();
} else {
// with the supplied value
for (ColorArray color : colorList) {
// Use a local state variable in case it gets overridden below
State cmpState = state;
if (color.getState() == null) {
logger.error("Error parsing color");
continue;
}
// If there's an item defined here, get its state
String itemName = color.getItem();
if (itemName != null) {
// Try and find the item to test.
// If it's not found, return visible
Item item;
try {
item = itemRegistry.getItem(itemName);
// Get the item state
cmpState = item.getState();
} catch (ItemNotFoundException e) {
logger.warn("Cannot retrieve color item {} for widget", color.getItem());
}
}
// Handle the sign
String value;
if (color.getSign() != null) {
value = color.getSign() + color.getState();
} else {
value = color.getState();
}
if (matchStateToValue(cmpState, value, color.getCondition()) == true) {
// We have the color for this value - break!
colorString = color.getArg();
break;
}
}
}
// Remove quotes off the colour - if they exist
if (colorString == null) {
return null;
}
if (colorString.startsWith("\"") && colorString.endsWith("\"")) {
colorString = colorString.substring(1, colorString.length() - 1);
}
return colorString;
}
Aggregations