Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
fixes handling of IRRADIANCE unit (#5602)
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and maggu2810 committed May 23, 2018
1 parent cc3b0c4 commit 78b2efb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.measure.quantity.Temperature;

import org.eclipse.smarthome.core.library.dimension.Density;
import org.eclipse.smarthome.core.library.dimension.Intensity;
import org.eclipse.smarthome.core.library.unit.ImperialUnits;
import org.eclipse.smarthome.core.library.unit.MetricPrefix;
import org.eclipse.smarthome.core.library.unit.SIUnits;
Expand Down Expand Up @@ -255,6 +256,24 @@ public void testDensity() {
assertEquals("19.816 g/cm³", density.toString());
}

@Test
public void testIntensity() {
QuantityType<Intensity> density = new QuantityType<>("10 W/m²");
assertEquals(10, density.doubleValue(), 1E-5);
assertEquals(SmartHomeUnits.IRRADIANCE.toString(), density.getUnit().toString());

density = density.toUnit("W/cm²");
assertEquals("0.001 W/cm²", density.toString());

density = new QuantityType<Intensity>(2, SmartHomeUnits.IRRADIANCE);
assertEquals(2, density.doubleValue(), 1E-5);
assertEquals("2 W/m²", density.toString());

density = new QuantityType<Intensity>("3 W/m^2");
assertEquals(3, density.doubleValue(), 1E-5);
assertEquals("3 W/m²", density.toString());
}

@Test
public void testEnergyUnits() {
QuantityType<Energy> energy = new QuantityType<>("28800 J");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String getName() {
static {
SimpleUnitFormat.getInstance().label(PARTS_PER_MILLION, "ppm");
SimpleUnitFormat.getInstance().label(DECIBEL, "dB");
SimpleUnitFormat.getInstance().label(IRRADIANCE, "W/m2");
SimpleUnitFormat.getInstance().label(IRRADIANCE, "W/");
SimpleUnitFormat.getInstance().label(DEGREE_ANGLE, "°");
SimpleUnitFormat.getInstance().label(WATT_SECOND, "Ws");
SimpleUnitFormat.getInstance().label(WATT_HOUR, "Wh");
Expand Down

0 comments on commit 78b2efb

Please sign in to comment.