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

Commit

Permalink
Set correct percent value for Rollershutter item
Browse files Browse the repository at this point in the history
When setting DecimalType state for a Rollershutter item,
the state should be converted to PercentType.
Otherwise the group functions will present an error
of factor 100.

Fixes #1845

Signed-off-by: Hans Hazelius <hans@hazelius.se>
  • Loading branch information
hazzeh committed Jul 10, 2016
1 parent 2ee2fc6 commit d7f7ee4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
@@ -0,0 +1,45 @@
package org.eclipse.smarthome.core.library.items;

import static org.junit.Assert.assertEquals;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.types.State;
import org.junit.Test;

public class RollershutterItemTest {

@Test
public void setState_stateDown_returnPercent100() {
RollershutterItem sut = new RollershutterItem("Test");
State state = UpDownType.DOWN;
sut.setState(state);
assertEquals(PercentType.HUNDRED, sut.getState());
}

@Test
public void setState_stateUp_returnPercent0() {
RollershutterItem sut = new RollershutterItem("Test");
State state = UpDownType.UP;
sut.setState(state);
assertEquals(PercentType.ZERO, sut.getState());
}

@Test
public void setState_statePercent50_returnPercent50() {
RollershutterItem sut = new RollershutterItem("Test");
State state = new PercentType(50);
sut.setState(state);
assertEquals(state, sut.getState());
}

@Test
public void setState_stateDecimal050_returnPercent50() {
RollershutterItem sut = new RollershutterItem("Test");
State state = new DecimalType(0.50);
sut.setState(state);
assertEquals(new PercentType(50), sut.getState());
}

}
Expand Up @@ -85,6 +85,8 @@ public void setState(State state) {
super.setState(PercentType.ZERO);
} else if (state == UpDownType.DOWN) {
super.setState(PercentType.HUNDRED);
} else if (state.getClass() == DecimalType.class) {
super.setState(new PercentType(((DecimalType) state).toBigDecimal().multiply(new BigDecimal(100))));
} else {
super.setState(state);
}
Expand Down

0 comments on commit d7f7ee4

Please sign in to comment.