This repository has been archived by the owner on May 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for volumetric flow rate units. (#6550)
* Add support for volumetric flow rate units. Flow rate can be exposed in volume (l, m3) per time unit (s, min, h, d). Solves #6549. Signed-off-by: Łukasz Dywicki <lukasz@dywicki.pl>
- Loading branch information
Showing
3 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...home.core.test/src/test/java/org/eclipse/smarthome/core/types/VolumetricFlowRateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.types; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import javax.measure.Unit; | ||
|
||
import org.eclipse.smarthome.core.library.dimension.VolumetricFlowRate; | ||
import org.eclipse.smarthome.core.library.unit.SmartHomeUnits; | ||
import org.eclipse.smarthome.core.types.util.UnitUtils; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import tec.uom.se.ComparableQuantity; | ||
import tec.uom.se.quantity.Quantities; | ||
|
||
/** | ||
* Test for volumentric flow rate constants defined in {@link SmartHomeUnits}. | ||
* | ||
* @author Łukasz Dywicki - initial contribution and API | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class VolumetricFlowRateTest { | ||
|
||
/** | ||
* While its not SI base unit it produces nice and fairly rounded numbers (si base is m3/s). | ||
*/ | ||
private final static Unit<VolumetricFlowRate> BASE_UNIT = SmartHomeUnits.CUBICMETRE_PER_HOUR; | ||
|
||
private final Unit<VolumetricFlowRate> unit; | ||
private final String symbol; | ||
private final Double value; | ||
private final Double valueInBaseUnit; | ||
|
||
public VolumetricFlowRateTest(Unit<VolumetricFlowRate> unit, String symbol, Double value, Double valueInBaseUnit) { | ||
this.unit = unit; | ||
this.symbol = symbol; | ||
this.value = value; | ||
this.valueInBaseUnit = valueInBaseUnit; | ||
} | ||
|
||
/** | ||
* An additional test which converts given test quantity into base unit and then compares it with expected value. | ||
* | ||
* This basic test confirms that values of different flow rates can be exchanged to given base unit. | ||
*/ | ||
@Test | ||
public void testValueConversionToM3s() { | ||
ComparableQuantity<VolumetricFlowRate> quantity = Quantities.getQuantity(value, unit); | ||
ComparableQuantity<VolumetricFlowRate> quantityInBase = Quantities.getQuantity(valueInBaseUnit, BASE_UNIT); | ||
|
||
ComparableQuantity<VolumetricFlowRate> convertedQuantity = quantity.to(BASE_UNIT); | ||
|
||
assertThat(convertedQuantity, is(equalTo(quantityInBase))); | ||
} | ||
|
||
/** | ||
* Verifies that given symbol is recognized by {@link UnitUtils}. | ||
*/ | ||
@Test | ||
public void testSymbolLookup() { | ||
Unit<?> parsedUnit = UnitUtils.parseUnit(symbol); | ||
|
||
assertThat(parsedUnit, is(notNullValue())); | ||
assertThat(parsedUnit, is(equalTo(unit))); | ||
} | ||
|
||
@Parameters | ||
public static Object[] params() { | ||
return new Object[] { new Object[] { SmartHomeUnits.LITRE_PER_MINUTE, "l/min", 100.0, 6.0 }, | ||
new Object[] { SmartHomeUnits.CUBICMETRE_PER_SECOND, "m³/s", 100.0, 360000.0 }, | ||
new Object[] { SmartHomeUnits.CUBICMETRE_PER_MINUTE, "m³/min", 100.0, 6000.0 }, | ||
new Object[] { SmartHomeUnits.CUBICMETRE_PER_HOUR, "m³/h", 100.0, 100.0 }, | ||
new Object[] { SmartHomeUnits.CUBICMETRE_PER_DAY, "m³/d", 100.0, 4.166666666666667 } }; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...e.core/src/main/java/org/eclipse/smarthome/core/library/dimension/VolumetricFlowRate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.library.dimension; | ||
|
||
import javax.measure.Quantity; | ||
|
||
/** | ||
* Define Volumetric Flow Rate type (basic unit is m^3/s). | ||
* | ||
* @author Łukasz Dywicki - initial contribution | ||
* | ||
*/ | ||
public interface VolumetricFlowRate extends Quantity<VolumetricFlowRate> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters