From 9292a3d164e5487a852434a413ef42bd6100a9e7 Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Tue, 3 Apr 2018 17:59:06 +0200 Subject: [PATCH] =?UTF-8?q?adds=20kW=C2=B7h=20as=20Unit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #5341 Signed-off-by: Jan N. Klug --- .../smarthome/core/library/types/QuantityTypeTest.java | 7 +++++++ .../smarthome/core/library/unit/SmartHomeUnits.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/library/types/QuantityTypeTest.java b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/library/types/QuantityTypeTest.java index 27ec3f5dedc..6703e42ee16 100644 --- a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/library/types/QuantityTypeTest.java +++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/library/types/QuantityTypeTest.java @@ -20,6 +20,7 @@ import javax.measure.Unit; import javax.measure.quantity.Dimensionless; +import javax.measure.quantity.Energy; import javax.measure.quantity.Length; import javax.measure.quantity.Temperature; @@ -244,4 +245,10 @@ public void testExponentials() { assertEquals(exponential, new QuantityType<>("10 km")); } + @Test + public void testEnergyUnits() { + QuantityType energy = new QuantityType<>("15000 J"); + assertEquals("0.004166666666666666666666666666666667 kWh", energy.toUnit("kWh").toString()); + assertEquals("15000 Ws", energy.toUnit("Ws").toString()); + } } diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java index 2be49b0ac94..0803da06fa5 100644 --- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java +++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/unit/SmartHomeUnits.java @@ -52,6 +52,7 @@ import tec.uom.se.function.PiMultiplierConverter; import tec.uom.se.function.RationalConverter; import tec.uom.se.unit.AlternateUnit; +import tec.uom.se.unit.ProductUnit; import tec.uom.se.unit.TransformedUnit; import tec.uom.se.unit.Units; @@ -122,6 +123,9 @@ public String getName() { public static final Unit