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

BasicUI: Treat Switch on NumberItem not as ON/OFF Switch #3493

Merged
merged 4 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down