Search in sources :

Example 16 with NumberItem

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

the class GroupItemTest method assertAcceptedCommandTypesOnGroupItemsReturnsSubsetOfCommandTypesSupportedByAllMembers.

@SuppressWarnings("unchecked")
@Test()
public void assertAcceptedCommandTypesOnGroupItemsReturnsSubsetOfCommandTypesSupportedByAllMembers() {
    SwitchItem switchItem = new SwitchItem("switch");
    NumberItem numberItem = new NumberItem("number");
    GroupItem groupItem = new GroupItem("group");
    groupItem.addMember(switchItem);
    groupItem.addMember(numberItem);
    assertThat(groupItem.getAcceptedCommandTypes(), hasItems(RefreshType.class));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) RefreshType(org.eclipse.smarthome.core.types.RefreshType) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 17 with NumberItem

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

the class ItemDTOMapperTest method testMapFunctionWithNumberItemAndCountFunction.

@Test
public void testMapFunctionWithNumberItemAndCountFunction() {
    // testing Group:Number:Count(".*hello.*")
    NumberItem item1 = new NumberItem("item1");
    GroupFunctionDTO gFuncDTO = new GroupFunctionDTO();
    gFuncDTO.name = "COUNT";
    gFuncDTO.params = new String[] { ".*hello.*" };
    GroupFunction gFunc = ItemDTOMapper.mapFunction(item1, gFuncDTO);
    assertThat(gFunc, instanceOf(ArithmeticGroupFunction.Count.class));
    assertThat(gFunc.getParameters().length, is(1));
    assertThat(gFunc.getParameters()[0], instanceOf(StringType.class));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) GroupFunction(org.eclipse.smarthome.core.items.GroupFunction) StringType(org.eclipse.smarthome.core.library.types.StringType) Test(org.junit.Test)

Example 18 with NumberItem

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

the class CoreItemFactoryTest method createNumberItemWithDimension.

@Test
public void createNumberItemWithDimension() {
    NumberItem numberItem = (NumberItem) coreItemFactory.createItem(CoreItemFactory.NUMBER + ":Temperature", "myNumberItem");
    assertThat(numberItem.getDimension(), equalTo(Temperature.class));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Temperature(javax.measure.quantity.Temperature) Test(org.junit.Test)

Example 19 with NumberItem

use of org.eclipse.smarthome.core.library.items.NumberItem 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 20 with NumberItem

use of org.eclipse.smarthome.core.library.items.NumberItem 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)

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