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