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());
}
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")));
}
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")));
}
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));
}
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());
}
Aggregations