use of org.eclipse.smarthome.core.library.items.NumberItem in project smarthome by eclipse.
the class GroupItemTest method assertThatNumberGroupItemWithDimensionCalculatesCorrectState.
@SuppressWarnings("null")
@Test
public void assertThatNumberGroupItemWithDimensionCalculatesCorrectState() {
NumberItem baseItem = createNumberItem("baseItem", Temperature.class, UnDefType.NULL);
GroupFunctionDTO gfDTO = new GroupFunctionDTO();
gfDTO.name = "sum";
GroupFunction function = groupFunctionHelper.createGroupFunction(gfDTO, Collections.emptyList(), Temperature.class);
GroupItem groupItem = new GroupItem("number", baseItem, function);
groupItem.setUnitProvider(unitProvider);
NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C"));
groupItem.addMember(celsius);
NumberItem fahrenheit = createNumberItem("F", Temperature.class, new QuantityType<Temperature>("23 °F"));
groupItem.addMember(fahrenheit);
NumberItem kelvin = createNumberItem("K", Temperature.class, new QuantityType<Temperature>("23 K"));
groupItem.addMember(kelvin);
QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
assertThat(state.getUnit(), is(Units.CELSIUS));
assertThat(state.doubleValue(), is(-232.15d));
celsius.setState(new QuantityType<Temperature>("265 °C"));
state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
assertThat(state.getUnit(), is(Units.CELSIUS));
assertThat(state.doubleValue(), is(9.85d));
}
use of org.eclipse.smarthome.core.library.items.NumberItem in project smarthome by eclipse.
the class StateDescriptionServiceImplTest method testServiceWithOneStateDescriptionProvider.
@Test
public void testServiceWithOneStateDescriptionProvider() {
StateDescriptionProvider stateDescriptionProviderDefault = mock(StateDescriptionProvider.class);
when(stateDescriptionProviderDefault.getRank()).thenReturn(STATE_DESCRIPTION_PROVIDER_DEFAULT_SERVICE_RANKING);
StateDescription stateDescription1 = new StateDescription(STATE_DESCRIPTION_PROVIDER_DEFAULT_MIN_VALUE, STATE_DESCRIPTION_PROVIDER_DEFAULT_MAX_VALUE, STATE_DESCRIPTION_PROVIDER_DEFAULT_STEP, STATE_DESCRIPTION_PROVIDER_DEFAULT_PATTERN, STATE_DESCRIPTION_PROVIDER_DEFAULT_IS_READONLY, STATE_DESCRIPTION_PROVIDER_DEFAULT_OPTIONS);
when(stateDescriptionProviderDefault.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription1);
mergingService.addStateDescriptionProvider(stateDescriptionProviderDefault);
item = new NumberItem(ITEM_NAME);
item.setStateDescriptionService(mergingService);
StateDescription finalStateDescription = item.getStateDescription();
assertThat(finalStateDescription.getMinimum(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_MIN_VALUE));
assertThat(finalStateDescription.getMaximum(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_MAX_VALUE));
assertThat(finalStateDescription.getStep(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_STEP));
assertThat(finalStateDescription.getPattern(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_PATTERN));
assertThat(finalStateDescription.isReadOnly(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_IS_READONLY));
assertThat(finalStateDescription.getOptions(), is(STATE_DESCRIPTION_PROVIDER_DEFAULT_OPTIONS));
}
use of org.eclipse.smarthome.core.library.items.NumberItem in project smarthome by eclipse.
the class StateDescriptionServiceImplTest method mergeStateDescriptions.
private StateDescription mergeStateDescriptions(StateDescription stateDescription1, StateDescription stateDescription2, int stateDescriptionProvider1ServiceRanking, int stateDescriptionProvider2ServiceRanking) {
StateDescriptionProvider stateDescriptionProvider1 = mock(StateDescriptionProvider.class);
StateDescriptionProvider stateDescriptionProvider2 = mock(StateDescriptionProvider.class);
when(stateDescriptionProvider1.getRank()).thenReturn(stateDescriptionProvider1ServiceRanking);
when(stateDescriptionProvider2.getRank()).thenReturn(stateDescriptionProvider2ServiceRanking);
when(stateDescriptionProvider1.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription1);
when(stateDescriptionProvider2.getStateDescription(ITEM_NAME, null)).thenReturn(stateDescription2);
mergingService.addStateDescriptionProvider(stateDescriptionProvider1);
mergingService.addStateDescriptionProvider(stateDescriptionProvider2);
item = new NumberItem(ITEM_NAME);
item.setStateDescriptionService(mergingService);
StateDescription finalStateDescription = item.getStateDescription();
return finalStateDescription;
}
use of org.eclipse.smarthome.core.library.items.NumberItem 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));
}
use of org.eclipse.smarthome.core.library.items.NumberItem 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));
}
Aggregations