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

adds kW·h as Unit #5346

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -244,4 +245,10 @@ public void testExponentials() {
assertEquals(exponential, new QuantityType<>("10 km"));
}

@Test
public void testEnergyUnits() {
QuantityType<Energy> energy = new QuantityType<>("15000 J");
assertEquals("0.004166666666666666666666666666666667 kWh", energy.toUnit("kWh").toString());
assertEquals("15000 Ws", energy.toUnit("Ws").toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -122,13 +123,19 @@ public String getName() {
public static final Unit<Time> WEEK = addUnit(Units.WEEK);
public static final Unit<Time> YEAR = addUnit(Units.YEAR);
public static final Unit<Volume> LITRE = addUnit(Units.LITRE);
public static final Unit<Energy> WATT_SECOND = addUnit(new ProductUnit<Energy>(Units.WATT.multiply(Units.SECOND)));
public static final Unit<Energy> WATT_HOUR = addUnit(WATT_SECOND.multiply(3600));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but maybe we should define WATT_HOUR also by ProductUnit with Units.HOUR. It already has the factor defined.

public static final Unit<Energy> KILOWATT_HOUR = addUnit(WATT_HOUR.multiply(1000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use the KILO prefix here:

import static org.eclipse.smarthome.core.library.unit.MetricPrefix.KILO;

// and

public static final Unit<Energy> KILOWATT_HOUR = addUnit(KILO(WATT_HOUR));


/**
* Add unit symbols for custom ESH units.
*/
static {
SimpleUnitFormat.getInstance().label(IRRADIANCE, "W/m2");
SimpleUnitFormat.getInstance().label(DEGREE_ANGLE, "°");
SimpleUnitFormat.getInstance().label(WATT_SECOND, "Ws");
SimpleUnitFormat.getInstance().label(WATT_HOUR, "Wh");
SimpleUnitFormat.getInstance().label(KILOWATT_HOUR, "kWh");
}

/**
Expand Down