Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
BasicUI: Treat Switch on NumberItem not as ON/OFF Switch (#3493)
Browse files Browse the repository at this point in the history
* BasicUI: Treat Switch on NumberItem not as ON/OFF Switch
* Only convert state of plain switches without mappings
* Fix exception in test due to new check in implementation
* Test for state conversion on switch with mapping

Fixes #3472
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
  • Loading branch information
triller-telekom authored and Simon Kaufmann committed May 22, 2017
1 parent 38b3e20 commit 1b2ab9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Mapping>());

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<Mapping> mappings = new BasicEList<Mapping>();
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,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
Expand Down

0 comments on commit 1b2ab9f

Please sign in to comment.