Search in sources :

Example 21 with NumberItem

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));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) Temperature(javax.measure.quantity.Temperature) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 22 with NumberItem

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));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 23 with NumberItem

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;
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 24 with NumberItem

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));
}
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 25 with NumberItem

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));
}
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

NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)34 Test (org.junit.Test)25 Item (org.eclipse.smarthome.core.items.Item)17 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)15 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)13 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)12 State (org.eclipse.smarthome.core.types.State)11 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)6 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)5 StateDescription (org.eclipse.smarthome.core.types.StateDescription)5 Temperature (javax.measure.quantity.Temperature)4 GroupItem (org.eclipse.smarthome.core.items.GroupItem)4 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)4 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)4 StateDescriptionProvider (org.eclipse.smarthome.core.types.StateDescriptionProvider)3 Collection (java.util.Collection)2 Length (javax.measure.quantity.Length)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 UnitProvider (org.eclipse.smarthome.core.i18n.UnitProvider)2 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)2