Search in sources :

Example 26 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class GroupItemTest method assertThatGroupItemWithRollershutterBaseItemConversionWorks.

@Test
public void assertThatGroupItemWithRollershutterBaseItemConversionWorks() {
    // initially this group has State UndefType.NULL
    GroupItem groupItem = new GroupItem("root", new RollershutterItem("myRollerShutter"));
    State groupStateAsOnOff = groupItem.getStateAs(OnOffType.class);
    // a state conversion from NULL to OnOffType should not be possible
    assertNull(groupStateAsOnOff);
    // init group
    groupItem.setState(new PercentType(70));
    groupStateAsOnOff = groupItem.getStateAs(OnOffType.class);
    // any value >0 means on, so 50% means the group state should be ON
    assertTrue(OnOffType.ON.equals(groupStateAsOnOff));
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) State(org.eclipse.smarthome.core.types.State) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 27 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class GroupItemTest method assertThatGroupItemWithColoritemBaseItemConversionWorks.

@Test
public void assertThatGroupItemWithColoritemBaseItemConversionWorks() {
    // initially this group has State UndefType.NULL
    GroupItem groupItem = new GroupItem("root", new ColorItem("myColor"));
    State groupStateAsPercent = groupItem.getStateAs(PercentType.class);
    // a state conversion from NULL to PercentType should not be possible
    assertNull(groupStateAsPercent);
    // init group
    groupItem.setState(new HSBType("200,80,80"));
    groupStateAsPercent = groupItem.getStateAs(PercentType.class);
    assertTrue(groupStateAsPercent instanceof PercentType);
    assertThat(((PercentType) groupStateAsPercent).intValue(), is(80));
}
Also used : State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 28 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class ColorItemTest method testSetStateWithHSBType.

@Test
public void testSetStateWithHSBType() {
    ColorItem item = new ColorItem("test");
    item.setState(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)));
    assertEquals(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)), item.getState());
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 29 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class ColorItemTest method testSetStateWithPercentType.

@Test
public void testSetStateWithPercentType() {
    ColorItem item = new ColorItem("test");
    item.setState(new PercentType(50));
    assertEquals(new HSBType(new DecimalType(0), new PercentType(0), new PercentType(50)), item.getState());
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 30 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class DimmerItemTest method getAsPercentFromPercent.

@Test
public void getAsPercentFromPercent() {
    final BigDecimal origin = new BigDecimal(25);
    final DimmerItem item = createDimmerItem(new PercentType(origin));
    final BigDecimal result = getState(item, PercentType.class);
    assertEquals(origin.compareTo(result), 0);
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

PercentType (org.eclipse.smarthome.core.library.types.PercentType)63 Test (org.junit.Test)25 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)17 State (org.eclipse.smarthome.core.types.State)17 HSBType (org.eclipse.smarthome.core.library.types.HSBType)16 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)13 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)9 StringType (org.eclipse.smarthome.core.library.types.StringType)9 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 BigDecimal (java.math.BigDecimal)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 LinkedList (java.util.LinkedList)2