Search in sources :

Example 6 with HSBType

use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSwitchWidgetThroughGetState.

@Test
public void testStateConversionForSwitchWidgetThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");
    when(switchWidget.getMappings()).thenReturn(new BasicEList<Mapping>());
    State stateForSwitch = uiRegistry.getState(switchWidget);
    assertEquals(OnOffType.ON, stateForSwitch);
}
Also used : Switch(org.eclipse.smarthome.model.sitemap.Switch) State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Mapping(org.eclipse.smarthome.model.sitemap.Mapping) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 7 with HSBType

use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSliderWidgetThroughGetState.

@Test
public void testStateConversionForSliderWidgetThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,75");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Slider sliderWidget = mock(Slider.class);
    when(sliderWidget.getItem()).thenReturn("myItem");
    State stateForSlider = uiRegistry.getState(sliderWidget);
    assertTrue(stateForSlider instanceof PercentType);
    PercentType pt = (PercentType) stateForSlider;
    assertEquals(75, pt.longValue());
}
Also used : Slider(org.eclipse.smarthome.model.sitemap.Slider) State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 8 with HSBType

use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSwitchWidgetWithMappingThroughGetState.

@Test
public void testStateConversionForSwitchWidgetWithMappingThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");
    Mapping mapping = mock(Mapping.class);
    BasicEList<Mapping> mappings = new BasicEList<Mapping>();
    mappings.add(mapping);
    when(switchWidget.getMappings()).thenReturn(mappings);
    State stateForSwitch = uiRegistry.getState(switchWidget);
    assertEquals(colorState, stateForSwitch);
}
Also used : Switch(org.eclipse.smarthome.model.sitemap.Switch) State(org.eclipse.smarthome.core.types.State) BasicEList(org.eclipse.emf.common.util.BasicEList) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Mapping(org.eclipse.smarthome.model.sitemap.Mapping) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 9 with HSBType

use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.

the class ColorpickerRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Colorpicker cp = (Colorpicker) w;
    String snippetName = "colorpicker";
    String snippet = getSnippet(snippetName);
    // set the default send-update frequency to 200ms
    String frequency = cp.getFrequency() == 0 ? "200" : Integer.toString(cp.getFrequency());
    // get RGB hex value
    State state = itemUIRegistry.getState(cp);
    String hexValue = "#ffffff";
    if (state instanceof HSBType) {
        HSBType hsbState = (HSBType) state;
        hexValue = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
    }
    String purelabel = itemUIRegistry.getLabel(w);
    purelabel = purelabel.replaceAll("\\\"", "\\\\'");
    // Should be called before preprocessSnippet
    snippet = StringUtils.replace(snippet, "%state%", hexValue);
    snippet = StringUtils.replace(snippet, "%icon_state%", escapeURL(hexValue));
    snippet = preprocessSnippet(snippet, w);
    snippet = StringUtils.replace(snippet, "%purelabel%", purelabel);
    snippet = StringUtils.replace(snippet, "%frequency%", frequency);
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
    String style = "";
    String color = itemUIRegistry.getLabelColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%labelstyle%", style);
    style = "";
    color = itemUIRegistry.getValueColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%valuestyle%", style);
    sb.append(snippet);
    return null;
}
Also used : State(org.eclipse.smarthome.core.types.State) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Colorpicker(org.eclipse.smarthome.model.sitemap.Colorpicker)

Example 10 with HSBType

use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.

the class ColorItemTest method testUpdateStateWithPercentType.

@Test
public void testUpdateStateWithPercentType() {
    ColorItem item = new ColorItem("test");
    item.setState(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)));
    item.setState(new PercentType(50));
    assertEquals(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(50)), item.getState());
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Aggregations

HSBType (org.eclipse.smarthome.core.library.types.HSBType)34 Test (org.junit.Test)19 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 State (org.eclipse.smarthome.core.types.State)10 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)3 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)3 StringType (org.eclipse.smarthome.core.library.types.StringType)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)2 RefreshType (org.eclipse.smarthome.core.types.RefreshType)2 Colorpicker (org.eclipse.smarthome.model.sitemap.Colorpicker)2 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)2 Switch (org.eclipse.smarthome.model.sitemap.Switch)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Locale (java.util.Locale)1 MissingResourceException (java.util.MissingResourceException)1