Search in sources :

Example 16 with SwitchItem

use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.

the class ArithmeticGroupFunctionTest method testOrFunction_differntTypes.

@Test
public void testOrFunction_differntTypes() {
    DimmerItem dimmer1 = new DimmerItem("TestDimmer1");
    dimmer1.setState(new PercentType("42"));
    DimmerItem dimmer2 = new DimmerItem("TestDimmer2");
    dimmer2.setState(new DecimalType("0"));
    SwitchItem switch1 = new SwitchItem("TestSwitch1");
    switch1.setState(OnOffType.ON);
    SwitchItem switch2 = new SwitchItem("TestSwitch2");
    switch2.setState(OnOffType.OFF);
    items.add(dimmer1);
    items.add(dimmer2);
    items.add(switch1);
    items.add(switch2);
    function = new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF);
    State state = function.calculate(items);
    State decimalState = function.getStateAs(items, DecimalType.class);
    assertEquals(OnOffType.ON, state);
    assertEquals(new DecimalType("2"), decimalState);
}
Also used : State(org.eclipse.smarthome.core.types.State) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Test(org.junit.Test)

Example 17 with SwitchItem

use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.

the class GenericItemProvider2Test method testGroupItemIsSame.

@Test
public void testGroupItemIsSame() {
    GenericItemProvider gip = new GenericItemProvider();
    GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    GroupItem g2 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    assertFalse(gip.hasItemChanged(g1, g2));
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 18 with SwitchItem

use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.

the class GenericItemProvider2Test method testGroupItemChangesFunctionParameters.

@Test
public void testGroupItemChangesFunctionParameters() {
    GenericItemProvider gip = new GenericItemProvider();
    GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    GroupItem g2 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, UnDefType.UNDEF));
    assertTrue(gip.hasItemChanged(g1, g2));
}
Also used : GroupItem(org.eclipse.smarthome.core.items.GroupItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 19 with SwitchItem

use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.

the class GenericItemProvider2Test method testGroupItemChangesBaseItemAndFunction.

@Test
public void testGroupItemChangesBaseItemAndFunction() {
    GenericItemProvider gip = new GenericItemProvider();
    GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    GroupItem g2 = new GroupItem("testGroup", new NumberItem("number"), new ArithmeticGroupFunction.Sum());
    assertTrue(gip.hasItemChanged(g1, g2));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 20 with SwitchItem

use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.

the class GenericItemProvider2Test method testGroupItemChangesBaseItem.

@Test
public void testGroupItemChangesBaseItem() {
    GenericItemProvider gip = new GenericItemProvider();
    GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    GroupItem g2 = new GroupItem("testGroup", new NumberItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF));
    assertTrue(gip.hasItemChanged(g1, g2));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) GroupItem(org.eclipse.smarthome.core.items.GroupItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)24 Test (org.junit.Test)17 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)16 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)11 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)9 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)9 Before (org.junit.Before)9 GroupItem (org.eclipse.smarthome.core.items.GroupItem)7 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)7 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)7 State (org.eclipse.smarthome.core.types.State)7 Item (org.eclipse.smarthome.core.items.Item)6 StringType (org.eclipse.smarthome.core.library.types.StringType)6 Temperature (javax.measure.quantity.Temperature)5 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)5 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4