Search in sources :

Example 1 with ColorArray

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) VisibilityRule(org.eclipse.smarthome.model.sitemap.VisibilityRule) BasicEList(org.eclipse.emf.common.util.BasicEList) Widget(org.eclipse.smarthome.model.sitemap.Widget) ColorArray(org.eclipse.smarthome.model.sitemap.ColorArray)

Example 2 with ColorArray

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;
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) CallItem(org.eclipse.smarthome.core.library.items.CallItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) DateTimeItem(org.eclipse.smarthome.core.library.items.DateTimeItem) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) LocationItem(org.eclipse.smarthome.core.library.items.LocationItem) ContactItem(org.eclipse.smarthome.core.library.items.ContactItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) PlayerItem(org.eclipse.smarthome.core.library.items.PlayerItem) ImageItem(org.eclipse.smarthome.core.library.items.ImageItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) State(org.eclipse.smarthome.core.types.State) ColorArray(org.eclipse.smarthome.model.sitemap.ColorArray) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Aggregations

ColorArray (org.eclipse.smarthome.model.sitemap.ColorArray)2 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EClass (org.eclipse.emf.ecore.EClass)1 GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 GroupItem (org.eclipse.smarthome.core.items.GroupItem)1 Item (org.eclipse.smarthome.core.items.Item)1 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)1 CallItem (org.eclipse.smarthome.core.library.items.CallItem)1 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)1 ContactItem (org.eclipse.smarthome.core.library.items.ContactItem)1 DateTimeItem (org.eclipse.smarthome.core.library.items.DateTimeItem)1 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)1 ImageItem (org.eclipse.smarthome.core.library.items.ImageItem)1 LocationItem (org.eclipse.smarthome.core.library.items.LocationItem)1 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)1 PlayerItem (org.eclipse.smarthome.core.library.items.PlayerItem)1 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)1 StringItem (org.eclipse.smarthome.core.library.items.StringItem)1 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)1 State (org.eclipse.smarthome.core.types.State)1