mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Added dimension for calorific value and related unit (#5327)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
@@ -161,6 +161,7 @@
|
||||
<xs:enumeration value="Number:Angle"/>
|
||||
<xs:enumeration value="Number:Area"/>
|
||||
<xs:enumeration value="Number:ArealDensity"/>
|
||||
<xs:enumeration value="Number:CalorificValue"/>
|
||||
<xs:enumeration value="Number:CatalyticActivity"/>
|
||||
<xs:enumeration value="Number:Currency"/>
|
||||
<xs:enumeration value="Number:DataAmount"/>
|
||||
|
||||
+2
@@ -69,6 +69,7 @@ import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.i18n.TranslationProvider;
|
||||
import org.openhab.core.i18n.UnitProvider;
|
||||
import org.openhab.core.library.dimension.ArealDensity;
|
||||
import org.openhab.core.library.dimension.CalorificValue;
|
||||
import org.openhab.core.library.dimension.Currency;
|
||||
import org.openhab.core.library.dimension.DataAmount;
|
||||
import org.openhab.core.library.dimension.DataTransferRate;
|
||||
@@ -400,6 +401,7 @@ public class I18nProviderImpl
|
||||
addDefaultUnit(dimensionMap, Angle.class, Units.DEGREE_ANGLE, Units.DEGREE_ANGLE);
|
||||
addDefaultUnit(dimensionMap, Area.class, SIUnits.SQUARE_METRE, ImperialUnits.SQUARE_FOOT);
|
||||
addDefaultUnit(dimensionMap, ArealDensity.class, Units.DOBSON_UNIT);
|
||||
addDefaultUnit(dimensionMap, CalorificValue.class, Units.KILOWATT_HOUR_PER_CUBICMETRE);
|
||||
addDefaultUnit(dimensionMap, CatalyticActivity.class, Units.KATAL);
|
||||
addDefaultUnit(dimensionMap, Currency.class, CurrencyUnits.BASE_CURRENCY);
|
||||
addDefaultUnit(dimensionMap, DataAmount.class, Units.BYTE);
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2026 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.core.library.dimension;
|
||||
|
||||
import javax.measure.Quantity;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* This interface represents the calorific value (a.k.a. heating value or energy value) dimension.
|
||||
*
|
||||
* @author Christoph Weitkamp - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface CalorificValue extends Quantity<CalorificValue> {
|
||||
|
||||
}
|
||||
@@ -52,6 +52,7 @@ import javax.measure.spi.SystemOfUnits;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.library.dimension.ArealDensity;
|
||||
import org.openhab.core.library.dimension.CalorificValue;
|
||||
import org.openhab.core.library.dimension.DataAmount;
|
||||
import org.openhab.core.library.dimension.DataTransferRate;
|
||||
import org.openhab.core.library.dimension.Density;
|
||||
@@ -145,6 +146,8 @@ public final class Units extends CustomUnits {
|
||||
new ProductUnit<>(tech.units.indriya.unit.Units.WATT.multiply(tech.units.indriya.unit.Units.HOUR)));
|
||||
public static final Unit<Energy> KILOWATT_HOUR = addUnit(MetricPrefix.KILO(WATT_HOUR));
|
||||
public static final Unit<Energy> MEGAWATT_HOUR = addUnit(MetricPrefix.MEGA(WATT_HOUR));
|
||||
public static final Unit<CalorificValue> KILOWATT_HOUR_PER_CUBICMETRE = addUnit(
|
||||
new ProductUnit<>(KILOWATT_HOUR.divide(tech.units.indriya.unit.Units.CUBIC_METRE)));
|
||||
public static final Unit<EmissionIntensity> GRAM_PER_KILOWATT_HOUR = addUnit(
|
||||
new ProductUnit<>(tech.units.indriya.unit.Units.GRAM.divide(KILOWATT_HOUR)));
|
||||
public static final Unit<Power> VAR = addUnit(new AlternateUnit<>(tech.units.indriya.unit.Units.WATT, "var"));
|
||||
@@ -302,6 +305,7 @@ public final class Units extends CustomUnits {
|
||||
SimpleUnitFormat.getInstance().label(KILOVAR_HOUR, "kvarh");
|
||||
SimpleUnitFormat.getInstance().label(KILOVOLT_AMPERE, "kVA");
|
||||
SimpleUnitFormat.getInstance().label(KILOWATT_HOUR, "kWh");
|
||||
SimpleUnitFormat.getInstance().label(KILOWATT_HOUR_PER_CUBICMETRE, "kWh/m³");
|
||||
SimpleUnitFormat.getInstance().label(KNOT, KNOT.getSymbol());
|
||||
SimpleUnitFormat.getInstance().alias(LITRE, "dm³");
|
||||
SimpleUnitFormat.getInstance().label(LITRE_PER_MINUTE, "l/min");
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.IsEqual;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.core.library.dimension.ArealDensity;
|
||||
import org.openhab.core.library.dimension.CalorificValue;
|
||||
import org.openhab.core.library.dimension.Density;
|
||||
import org.openhab.core.library.dimension.Intensity;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
@@ -115,6 +116,17 @@ public class UnitsTest {
|
||||
assertThat(Units.MILLIMETRE_OF_MERCURY.toString(), is("mmHg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKiloWattHourPerCubicMetreUnitSymbolAndConversion() {
|
||||
assertThat(Units.KILOWATT_HOUR_PER_CUBICMETRE.toString(), is("kWh/m³"));
|
||||
|
||||
Quantity<CalorificValue> calorificValue = Quantities.getQuantity(new BigDecimal("10.183"),
|
||||
Units.KILOWATT_HOUR_PER_CUBICMETRE);
|
||||
Quantity<Volume> volume = Quantities.getQuantity(new BigDecimal("100"), SIUnits.CUBIC_METRE);
|
||||
Quantity<?> energy = volume.multiply(calorificValue);
|
||||
assertThat(energy.getUnit(), is(Units.KILOWATT_HOUR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGramPerKiloWattHourUnitSymbol() {
|
||||
assertThat(Units.GRAM_PER_KILOWATT_HOUR.toString(), is("g/kWh"));
|
||||
|
||||
Reference in New Issue
Block a user