Search in sources :

Example 66 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class NumberItemTest method setPercentType.

@Test
public void setPercentType() {
    NumberItem item = new NumberItem("test");
    State percent = new PercentType(50);
    item.setState(percent);
    assertEquals(percent, item.getState());
}
Also used : State(org.eclipse.smarthome.core.types.State) PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 67 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class ItemStateConverterImplTest method numberItemWitDimensionShouldConvertToLocaleBasedUnit.

@Test
public void numberItemWitDimensionShouldConvertToLocaleBasedUnit() {
    NumberItem item = mock(NumberItem.class);
    doReturn(Temperature.class).when(item).getDimension();
    UnitProvider unitProvider = mock(UnitProvider.class);
    when(unitProvider.getUnit(Temperature.class)).thenReturn(ImperialUnits.FAHRENHEIT);
    itemStateConverter.setUnitProvider(unitProvider);
    State originalState = new QuantityType<>("12.34 °C");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
    assertThat(convertedState, is(new QuantityType<>("54.212 °F")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) UnitProvider(org.eclipse.smarthome.core.i18n.UnitProvider) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 68 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class ItemStateConverterImplTest method numberItemWithoutDimensionShouldConvertToDecimalType.

@Test
public void numberItemWithoutDimensionShouldConvertToDecimalType() {
    Item item = new NumberItem("number");
    State originalState = new QuantityType<>("12.34 °C");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
    assertThat(convertedState, is(new DecimalType("12.34")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 69 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class GroupItemTest method testGetStateAs_shouldEqualStateUpdate.

@Test
public void testGetStateAs_shouldEqualStateUpdate() {
    // Main group uses AND function
    GroupItem rootGroupItem = new GroupItem("root", new SwitchItem("baseItem"), new ArithmeticGroupFunction.And(OnOffType.ON, OnOffType.OFF));
    rootGroupItem.setItemStateConverter(itemStateConverter);
    TestItem member1 = new TestItem("member1");
    rootGroupItem.addMember(member1);
    TestItem member2 = new TestItem("member2");
    rootGroupItem.addMember(member2);
    // Sub-group uses NAND function
    GroupItem subGroup = new GroupItem("subGroup1", new SwitchItem("baseItem"), new ArithmeticGroupFunction.NAnd(OnOffType.ON, OnOffType.OFF));
    TestItem subMember = new TestItem("subGroup member 1");
    subGroup.addMember(subMember);
    rootGroupItem.addMember(subGroup);
    member1.setState(OnOffType.ON);
    member2.setState(OnOffType.ON);
    subMember.setState(OnOffType.OFF);
    // subGroup and subMember state differ
    assertThat(subGroup.getStateAs(OnOffType.class), is(OnOffType.ON));
    assertThat(subMember.getStateAs(OnOffType.class), is(OnOffType.OFF));
    // We expect ON here
    State getStateAsState = rootGroupItem.getStateAs(OnOffType.class);
    // recalculate the state
    rootGroupItem.stateUpdated(member1, UnDefType.NULL);
    State stateUpdatedState = rootGroupItem.getState();
    assertThat(getStateAsState, is(OnOffType.ON));
    assertThat(stateUpdatedState, is(OnOffType.ON));
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) State(org.eclipse.smarthome.core.types.State) 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 70 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class NumberItemTest method setHSBType.

@Test
public void setHSBType() {
    NumberItem item = new NumberItem("test");
    State hsb = new HSBType("5,23,42");
    item.setState(hsb);
    assertEquals(hsb, item.getState());
}
Also used : State(org.eclipse.smarthome.core.types.State) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Aggregations

State (org.eclipse.smarthome.core.types.State)130 Test (org.junit.Test)59 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)23 PercentType (org.eclipse.smarthome.core.library.types.PercentType)22 Item (org.eclipse.smarthome.core.items.Item)21 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)19 Temperature (javax.measure.quantity.Temperature)18 StringType (org.eclipse.smarthome.core.library.types.StringType)18 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)17 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)15 HSBType (org.eclipse.smarthome.core.library.types.HSBType)15 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)15 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)13 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)13 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)12 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)11 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)10 RawType (org.eclipse.smarthome.core.library.types.RawType)10 Pressure (javax.measure.quantity.Pressure)9 GroupItem (org.eclipse.smarthome.core.items.GroupItem)8