Skip to content

Commit

Permalink
further work
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K committed May 30, 2023
1 parent fcecf96 commit a0135bc
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
import org.openhab.core.library.dimension.Density;
import org.openhab.core.library.dimension.ElectricConductivity;
import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.dimension.EnergyPrice;
import org.openhab.core.library.dimension.RadiationSpecificActivity;
import org.openhab.core.library.dimension.Price;
import org.openhab.core.library.dimension.VolumetricFlowRate;
import org.openhab.core.library.types.PointType;
import org.openhab.core.library.unit.CurrencyProvider;
Expand Down Expand Up @@ -431,7 +431,7 @@ public static Map<Class<? extends Quantity<?>>, Map<SystemOfUnits, Unit<? extend
addDefaultUnit(dimensionMap, Mass.class, SIUnits.KILOGRAM, ImperialUnits.POUND);
addDefaultUnit(dimensionMap, Power.class, Units.WATT);
addDefaultUnit(dimensionMap, Pressure.class, HECTO(SIUnits.PASCAL), ImperialUnits.INCH_OF_MERCURY);
addDefaultUnit(dimensionMap, Price.class, CurrencyUnits.BASE_PRICE);
addDefaultUnit(dimensionMap, EnergyPrice.class, CurrencyUnits.BASE_ENERGY_PRICE);
addDefaultUnit(dimensionMap, RadiationDoseAbsorbed.class, Units.GRAY);
addDefaultUnit(dimensionMap, RadiationDoseEffective.class, Units.SIEVERT);
addDefaultUnit(dimensionMap, Radioactivity.class, Units.BECQUEREL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import tech.units.indriya.function.AbstractConverter;

/**
* The {@link CurrencyConverter} is a
* The {@link CurrencyConverter} implements an {@link UnitConverter} for {@link org.openhab.core.library.unit.CurrencyUnit}
*
* @author Jan N. Klug - Initial contribution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import tech.units.indriya.format.SimpleUnitFormat;

/**
* The {@link CurrencyService} is a
* The {@link CurrencyService} is allows to register and switch {@link CurrencyProvider}s and provides exchange rates for currencies
*
* @author Jan N. Klug - Initial contribution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link Price} defines the dimension for prices
* The {@link EnergyPrice} defines the dimension for prices
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault
public interface Price extends Quantity<Price> {
public interface EnergyPrice extends Quantity<EnergyPrice> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public Unit<Currency> divide(double divisor) {
}

private UnitConverter internalGetConverterTo(Unit<Currency> that) throws UnconvertibleException {
if (this.equals(that))
if (this.equals(that)) {
return AbstractConverter.IDENTITY;

}
if (BASE_CURRENCY.equals(this)) {
BigDecimal factor = CurrencyService.FACTOR_FCN.apply(that);
if (factor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.library.dimension.Currency;
import org.openhab.core.library.dimension.Price;
import org.openhab.core.library.dimension.EnergyPrice;

import tech.units.indriya.AbstractSystemOfUnits;
import tech.units.indriya.AbstractUnit;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.unit.ProductUnit;

Expand All @@ -37,11 +36,11 @@ public final class CurrencyUnits extends AbstractSystemOfUnits {
private static final CurrencyUnits INSTANCE = new CurrencyUnits();

public static final Unit<Currency> BASE_CURRENCY = new CurrencyUnit("DEF", null);
public static Unit<Price> BASE_PRICE = new ProductUnit<>(AbstractUnit.ONE.divide(BASE_CURRENCY));
public static Unit<EnergyPrice> BASE_ENERGY_PRICE = new ProductUnit<>(BASE_CURRENCY.divide(Units.KILOWATT_HOUR));

static {
addUnit(BASE_CURRENCY);
INSTANCE.units.add(BASE_PRICE);
INSTANCE.units.add(BASE_ENERGY_PRICE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<description><![CDATA[The location of this installation.<br>Coordinates as &lt;latitude&gt;,&lt;longitude&gt;[&lt;altitude&gt;]<br>Example: "52.5200066,13.4049540" (Berlin)]]></description>
</parameter>
<parameter name="baseCurrency" type="text" pattern="[A-Z]{3}">
<label>Base currency</label>
<label>Base Currency</label>
<description>The base currency of this system (determined by locale if not set)</description>
</parameter>
<parameter name="measurementSystem" type="text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
import java.util.function.Function;

import javax.measure.Unit;
import javax.measure.quantity.Energy;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.openhab.core.internal.library.unit.CurrencyConverter;
import org.openhab.core.internal.library.unit.CurrencyService;
import org.openhab.core.library.dimension.Currency;
import org.openhab.core.library.dimension.EnergyPrice;
import org.openhab.core.library.types.QuantityType;

/**
* The {@link CurrencyConverter} is a
* The {@link CurrencyUnitTest} contains tests for the currency units
*
* @author Jan N. Klug - Initial contribution
*/
Expand Down Expand Up @@ -74,8 +76,8 @@ public void testComplexConversion() {

@Test
public void testPriceCalculation() {
QuantityType<?> unitPrice = new QuantityType<>("0.25 €/kWh");
QuantityType<?> amount = new QuantityType<>("5 kWh");
QuantityType<EnergyPrice> unitPrice = new QuantityType<>("0.25 €/kWh");
QuantityType<Energy> amount = new QuantityType<>("5 kWh");
QuantityType<?> price = amount.multiply(unitPrice);

assertThat(price, is(notNullValue()));
Expand Down

0 comments on commit a0135bc

Please sign in to comment.