diff --git a/bundles/ui/org.eclipse.smarthome.ui.test/src/test/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImplTest.java b/bundles/ui/org.eclipse.smarthome.ui.test/src/test/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImplTest.java index 8f41e3f9a51..23cdcd60c06 100644 --- a/bundles/ui/org.eclipse.smarthome.ui.test/src/test/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImplTest.java +++ b/bundles/ui/org.eclipse.smarthome.ui.test/src/test/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImplTest.java @@ -13,6 +13,7 @@ import java.text.DecimalFormatSymbols; +import org.eclipse.emf.common.util.BasicEList; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.items.ItemNotFoundException; import org.eclipse.smarthome.core.items.ItemRegistry; @@ -26,6 +27,7 @@ import org.eclipse.smarthome.core.types.State; import org.eclipse.smarthome.core.types.StateDescription; import org.eclipse.smarthome.core.types.UnDefType; +import org.eclipse.smarthome.model.sitemap.Mapping; import org.eclipse.smarthome.model.sitemap.Sitemap; import org.eclipse.smarthome.model.sitemap.SitemapFactory; import org.eclipse.smarthome.model.sitemap.Slider; @@ -328,12 +330,36 @@ public void testStateConversionForSwitchWidgetThroughGetState() throws ItemNotFo Switch switchWidget = mock(Switch.class); when(switchWidget.getItem()).thenReturn("myItem"); + when(switchWidget.getMappings()).thenReturn(new BasicEList()); State stateForSwitch = uiRegistry.getState(switchWidget); assertEquals(OnOffType.ON, stateForSwitch); } + @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 mappings = new BasicEList(); + mappings.add(mapping); + when(switchWidget.getMappings()).thenReturn(mappings); + + State stateForSwitch = uiRegistry.getState(switchWidget); + + assertEquals(colorState, stateForSwitch); + } + @Test public void testStateConversionForSliderWidgetThroughGetState() throws ItemNotFoundException { State colorState = new HSBType("23,42,75"); diff --git a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java index 1bb4aaa5e53..afdc2a41fc7 100644 --- a/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/ui/org.eclipse.smarthome.ui/src/main/java/org/eclipse/smarthome/ui/internal/items/ItemUIRegistryImpl.java @@ -499,7 +499,10 @@ private State convertState(Widget w, Item i) { if (w instanceof Slider || (w instanceof Switch && i instanceof RollershutterItem)) { returnState = i.getStateAs(PercentType.class); } else if (w instanceof Switch) { - returnState = i.getStateAs(OnOffType.class); + Switch sw = (Switch) w; + if (sw.getMappings().size() == 0) { + returnState = i.getStateAs(OnOffType.class); + } } // if returnState is null, a conversion was not possible