javax.measure.quantity.Temperature Java Examples

The following examples show how to use javax.measure.quantity.Temperature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupItemOSGiTest.java    From openhab-core with Eclipse Public License 2.0 7 votes vote down vote up
@Test
public void assertThatNumberGroupItemWithDifferentDimensionsCalculatesCorrectState() {
    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);
    groupItem.setItemStateConverter(itemStateConverter);

    NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<>("23 °C"));
    groupItem.addMember(celsius);
    NumberItem hectoPascal = createNumberItem("F", Pressure.class, new QuantityType<>("1010 hPa"));
    groupItem.addMember(hectoPascal);
    NumberItem percent = createNumberItem("K", Dimensionless.class, new QuantityType<>("110 %"));
    groupItem.addMember(percent);

    QuantityType<?> state = groupItem.getStateAs(QuantityType.class);

    assertThat(state, is(new QuantityType<>("23 °C")));

    groupItem.stateUpdated(celsius, UnDefType.NULL);
    assertThat(groupItem.getState(), is(new QuantityType<>("23 °C")));
}
 
Example #2
Source File: SystemOffsetProfile.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private @Nullable QuantityType<Temperature> handleTemperature(QuantityType<Temperature> qtState,
        QuantityType<Temperature> offset) {

    QuantityType<Temperature> finalOffset;

    // do the math in kelvin and afterwards convert it back to the unit of the state
    QuantityType<Temperature> kelvinState = qtState.toUnit(SmartHomeUnits.KELVIN);
    QuantityType<Temperature> kelvinOffset = offset.toUnit(SmartHomeUnits.KELVIN);

    if (offset.getUnit().equals(SIUnits.CELSIUS)) {
        finalOffset = kelvinOffset.add(ZERO_CELSIUS_IN_KELVIN.negate());
    } else if (offset.getUnit().equals(ImperialUnits.FAHRENHEIT)) {
        finalOffset = kelvinOffset.add(ZERO_FAHRENHEIT_IN_KELVIN.negate());
    } else {
        // offset is already in kelvin
        finalOffset = offset;
    }

    kelvinState = kelvinState.add(finalOffset);
    return kelvinState.toUnit(qtState.getUnit());
}
 
Example #3
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandler() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    State state = new QuantityType<>("23°C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #4
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandlerDecimalOffset() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3");

    State state = new QuantityType<>("23 °C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #5
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnCommandFromHandler() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    Command cmd = new QuantityType<>("23°C");
    offsetProfile.onCommandFromHandler(cmd);

    ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
    verify(callback, times(1)).sendCommand(capture.capture());

    Command result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #6
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromItem() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    State state = new QuantityType<>("23°C");
    offsetProfile.onStateUpdateFromItem(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).handleUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(20, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #7
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnCommandFromItem() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    Command cmd = new QuantityType<>("23°C");
    offsetProfile.onCommandFromItem(cmd);

    ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
    verify(callback, times(1)).handleCommand(capture.capture());

    Command result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(20, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #8
Source File: SystemOffsetProfileTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandlerFahrenheitOffset() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3 °F");

    State state = new QuantityType<>("23 °C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertThat(decResult.doubleValue(), is(closeTo(24.6666666666666666666666666666667d, 0.0000000000000001d)));
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #9
Source File: SystemOffsetProfile.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
private @Nullable QuantityType<Temperature> handleTemperature(QuantityType<Temperature> qtState,
        QuantityType<Temperature> offset) {
    QuantityType<Temperature> finalOffset;

    // do the math in kelvin and afterwards convert it back to the unit of the state
    QuantityType<Temperature> kelvinState = qtState.toUnit(SmartHomeUnits.KELVIN);
    QuantityType<Temperature> kelvinOffset = offset.toUnit(SmartHomeUnits.KELVIN);

    if (SIUnits.CELSIUS.equals(offset.getUnit())) {
        finalOffset = kelvinOffset.add(ZERO_CELSIUS_IN_KELVIN.negate());
    } else if (ImperialUnits.FAHRENHEIT.equals(offset.getUnit())) {
        finalOffset = kelvinOffset.add(ZERO_FAHRENHEIT_IN_KELVIN.negate());
    } else {
        // offset is already in kelvin
        finalOffset = offset;
    }

    kelvinState = kelvinState.add(finalOffset);
    return kelvinState.toUnit(qtState.getUnit());
}
 
Example #10
Source File: GroupItemTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatNumberGroupItemWithDifferentDimensionsCalculatesCorrectState() {
    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);
    groupItem.setItemStateConverter(itemStateConverter);

    NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C"));
    groupItem.addMember(celsius);
    NumberItem hectoPascal = createNumberItem("F", Pressure.class, new QuantityType<Pressure>("1010 hPa"));
    groupItem.addMember(hectoPascal);
    NumberItem percent = createNumberItem("K", Dimensionless.class, new QuantityType<Dimensionless>("110 %"));
    groupItem.addMember(percent);

    QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);

    assertThat(state, is(new QuantityType<Temperature>("23 °C")));

    groupItem.stateUpdated(celsius, UnDefType.NULL);
    assertThat(groupItem.getState(), is(new QuantityType<Temperature>("23 °C")));
}
 
Example #11
Source File: SystemOffsetProfileTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnCommandFromItem() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    Command cmd = new QuantityType<Temperature>("23°C");
    offsetProfile.onCommandFromItem(cmd);

    ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
    verify(callback, times(1)).handleCommand(capture.capture());

    Command result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(20, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #12
Source File: SystemOffsetProfileTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnCommandFromHandler() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    Command cmd = new QuantityType<Temperature>("23°C");
    offsetProfile.onCommandFromHandler(cmd);

    ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
    verify(callback, times(1)).sendCommand(capture.capture());

    Command result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #13
Source File: SystemOffsetProfileTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandler() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");

    State state = new QuantityType<Temperature>("23°C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #14
Source File: SystemOffsetProfileTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandlerFahrenheitOffset() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3 °F");

    State state = new QuantityType<Temperature>("23 °C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertThat(decResult.doubleValue(), is(closeTo(24.6666666666666666666666666666667d, 0.0000000000000001d)));
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #15
Source File: SystemOffsetProfileTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testQuantityTypeOnStateUpdateFromHandlerDecimalOffset() {
    ProfileCallback callback = mock(ProfileCallback.class);
    SystemOffsetProfile offsetProfile = createProfile(callback, "3");

    State state = new QuantityType<Temperature>("23 °C");
    offsetProfile.onStateUpdateFromHandler(state);

    ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
    verify(callback, times(1)).sendUpdate(capture.capture());

    State result = capture.getValue();
    @SuppressWarnings("unchecked")
    QuantityType<Temperature> decResult = (QuantityType<Temperature>) result;
    assertEquals(26, decResult.intValue());
    assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
 
Example #16
Source File: MeteoBlueHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private State getStateForType(String type, BigDecimal value) {
    State state = new DecimalType(value);

    if (type.equals("Number:Temperature")) {
        state = new QuantityType<Temperature>(value, SIUnits.CELSIUS);
    } else if (type.equals("Number:Length")) {
        state = new QuantityType<Length>(value, MILLI(SIUnits.METRE));
    } else if (type.equals("Number:Pressure")) {
        state = new QuantityType<Pressure>(value, HECTO(SIUnits.PASCAL));
    } else if (type.equals("Number:Speed")) {
        state = new QuantityType<Speed>(value, SIUnits.KILOMETRE_PER_HOUR);
    }

    return state;
}
 
Example #17
Source File: GroupItemTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@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));
}
 
Example #18
Source File: CoreItemFactoryTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void createNumberItemWithDimension() {
    NumberItem numberItem = (NumberItem) coreItemFactory.createItem(CoreItemFactory.NUMBER + ":Temperature",
            "myNumberItem");

    assertThat(numberItem.getDimension(), equalTo(Temperature.class));
}
 
Example #19
Source File: QuantityTypeTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void toFullStringShouldParseToEqualState() {
    QuantityType<Temperature> temp = new QuantityType<>("20 °C");

    assertThat(temp.toFullString(), is("20 °C"));
    assertThat(QuantityType.valueOf(temp.toFullString()), is(temp));
}
 
Example #20
Source File: QuantityTypeArithmeticGroupFunctionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void init() {
    initMocks(this);
    items = new LinkedHashSet<>();

    when(unitProvider.getUnit(Temperature.class)).thenReturn(Units.CELSIUS);
}
 
Example #21
Source File: QuantityTypeArithmeticGroupFunctionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSumFunctionQuantityType() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("23.54 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("89 °C")));
    items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
    items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("122.41 °C")));

    function = new QuantityTypeArithmeticGroupFunction.Sum(Temperature.class);
    State state = function.calculate(items);

    assertEquals(new QuantityType<Temperature>("234.95 °C"), state);
}
 
Example #22
Source File: QuantityTypeArithmeticGroupFunctionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSumFunctionQuantityTypeDifferentUnits() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("23.54 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("192.2 °F")));
    items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
    items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("395.56 K")));

    function = new QuantityTypeArithmeticGroupFunction.Sum(Temperature.class);
    State state = function.calculate(items);

    assertEquals(new QuantityType<Temperature>("234.95 °C"), state);
}
 
Example #23
Source File: ItemStateConverterImplTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@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")));
}
 
Example #24
Source File: ItemStateConverterImplTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void numberItemWitDimensionShouldConvertToItemStateDescriptionUnit() {
    NumberItem item = mock(NumberItem.class);
    StateDescription stateDescription = mock(StateDescription.class);
    when(item.getStateDescription()).thenReturn(stateDescription);
    doReturn(Temperature.class).when(item).getDimension();
    when(stateDescription.getPattern()).thenReturn("%.1f K");

    State originalState = new QuantityType<>("12.34 °C");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);

    assertThat(convertedState, is(new QuantityType<>("285.49 K")));
}
 
Example #25
Source File: UnitUtilsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetDimensionName() {
    assertThat(UnitUtils.getDimensionName(SIUnits.CELSIUS), is(Temperature.class.getSimpleName()));
    assertThat(UnitUtils.getDimensionName(SmartHomeUnits.KILOWATT_HOUR), is(Energy.class.getSimpleName()));
    assertThat(UnitUtils.getDimensionName(SmartHomeUnits.WATT), is(Power.class.getSimpleName()));
    assertThat(UnitUtils.getDimensionName(MetricPrefix.MEGA(SmartHomeUnits.KILOWATT_HOUR)),
            is(Energy.class.getSimpleName()));

    Unit<?> unit = UnitUtils.parseUnit("°F");
    assertNotNull(unit);
    assertThat(UnitUtils.getDimensionName(unit), is(Temperature.class.getSimpleName()));
    unit = UnitUtils.parseUnit("m");
    assertNotNull(unit);
    assertThat(UnitUtils.getDimensionName(unit), is(Length.class.getSimpleName()));
}
 
Example #26
Source File: UnitUtilsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void whenValidDimensionIsGiven_shouldCreateQuantityClass() {
    Class<? extends Quantity<?>> temperature = UnitUtils.parseDimension("Temperature");
    assertTrue(Temperature.class.isAssignableFrom(temperature));

    Class<? extends Quantity<?>> intensity = UnitUtils.parseDimension("Intensity");
    assertTrue(Intensity.class.isAssignableFrom(intensity));
}
 
Example #27
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCelsiusSpecialChar() {
    QuantityType<Temperature> celsius = new QuantityType<>("20 ℃");
    assertThat(celsius, is(new QuantityType<>("20 °C")));
    assertThat(celsius.toFullString(), is("20 °C"));

    assertThat(celsius.getUnit().toString(), is("°C"));
}
 
Example #28
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFahrenheit2Kelvin() {
    Quantity<Temperature> fahrenheit = Quantities.getQuantity(new BigDecimal("100"), ImperialUnits.FAHRENHEIT);

    Quantity<Temperature> kelvin = fahrenheit.to(SmartHomeUnits.KELVIN);
    assertThat(kelvin.getUnit(), is(SmartHomeUnits.KELVIN));
    assertThat(kelvin.getValue().doubleValue(), is(closeTo(310.92777777777777778d, DEFAULT_ERROR)));
}
 
Example #29
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKelvin2Fahrenheit2() {
    Quantity<Temperature> kelvin = Quantities.getQuantity(new BigDecimal("300"), SmartHomeUnits.KELVIN);

    assertThat(kelvin.to(ImperialUnits.FAHRENHEIT),
            is(Quantities.getQuantity(new BigDecimal("80.33"), ImperialUnits.FAHRENHEIT)));
}
 
Example #30
Source File: QuantityTypeArithmeticGroupFunctionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAvgFunctionQuantityTypeDifferentUnits() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("100 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("113 °F")));
    items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
    items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("294.15 K")));

    function = new QuantityTypeArithmeticGroupFunction.Avg(Temperature.class);
    State state = function.calculate(items);

    assertEquals(new QuantityType<Temperature>("55.33 °C"), state);
}