mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Add RadiationDoseRate dimension (#5418)
* add RadiationDoseRate unit * add unit test Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
This commit is contained in:
@@ -193,6 +193,7 @@
|
|||||||
<xs:enumeration value="Number:Pressure"/>
|
<xs:enumeration value="Number:Pressure"/>
|
||||||
<xs:enumeration value="Number:RadiationDoseAbsorbed"/>
|
<xs:enumeration value="Number:RadiationDoseAbsorbed"/>
|
||||||
<xs:enumeration value="Number:RadiationDoseEffective"/>
|
<xs:enumeration value="Number:RadiationDoseEffective"/>
|
||||||
|
<xs:enumeration value="Number:RadiationDoseRate"/>
|
||||||
<xs:enumeration value="Number:RadiationSpecificActivity"/>
|
<xs:enumeration value="Number:RadiationSpecificActivity"/>
|
||||||
<xs:enumeration value="Number:RadioactiveActivity"/>
|
<xs:enumeration value="Number:RadioactiveActivity"/>
|
||||||
<xs:enumeration value="Number:SolidAngle"/>
|
<xs:enumeration value="Number:SolidAngle"/>
|
||||||
|
|||||||
+2
@@ -79,6 +79,7 @@ import org.openhab.core.library.dimension.EmissionIntensity;
|
|||||||
import org.openhab.core.library.dimension.EnergyPrice;
|
import org.openhab.core.library.dimension.EnergyPrice;
|
||||||
import org.openhab.core.library.dimension.Intensity;
|
import org.openhab.core.library.dimension.Intensity;
|
||||||
import org.openhab.core.library.dimension.RadiantExposure;
|
import org.openhab.core.library.dimension.RadiantExposure;
|
||||||
|
import org.openhab.core.library.dimension.RadiationDoseRate;
|
||||||
import org.openhab.core.library.dimension.RadiationSpecificActivity;
|
import org.openhab.core.library.dimension.RadiationSpecificActivity;
|
||||||
import org.openhab.core.library.dimension.VolumePrice;
|
import org.openhab.core.library.dimension.VolumePrice;
|
||||||
import org.openhab.core.library.dimension.VolumetricFlowRate;
|
import org.openhab.core.library.dimension.VolumetricFlowRate;
|
||||||
@@ -431,6 +432,7 @@ public class I18nProviderImpl
|
|||||||
addDefaultUnit(dimensionMap, Mass.class, SIUnits.KILOGRAM, ImperialUnits.POUND);
|
addDefaultUnit(dimensionMap, Mass.class, SIUnits.KILOGRAM, ImperialUnits.POUND);
|
||||||
addDefaultUnit(dimensionMap, Power.class, Units.WATT);
|
addDefaultUnit(dimensionMap, Power.class, Units.WATT);
|
||||||
addDefaultUnit(dimensionMap, Pressure.class, HECTO(SIUnits.PASCAL), ImperialUnits.INCH_OF_MERCURY);
|
addDefaultUnit(dimensionMap, Pressure.class, HECTO(SIUnits.PASCAL), ImperialUnits.INCH_OF_MERCURY);
|
||||||
|
addDefaultUnit(dimensionMap, RadiationDoseRate.class, Units.SIEVERT_PER_HOUR);
|
||||||
addDefaultUnit(dimensionMap, RadiationDoseAbsorbed.class, Units.GRAY);
|
addDefaultUnit(dimensionMap, RadiationDoseAbsorbed.class, Units.GRAY);
|
||||||
addDefaultUnit(dimensionMap, RadiationDoseEffective.class, Units.SIEVERT);
|
addDefaultUnit(dimensionMap, RadiationDoseEffective.class, Units.SIEVERT);
|
||||||
addDefaultUnit(dimensionMap, RadiationSpecificActivity.class, Units.BECQUEREL_PER_CUBIC_METRE);
|
addDefaultUnit(dimensionMap, RadiationSpecificActivity.class, Units.BECQUEREL_PER_CUBIC_METRE);
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radiation dose per time (basic unit is Sv/h)
|
||||||
|
*
|
||||||
|
* @author Bernd Weymann - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public interface RadiationDoseRate extends Quantity<RadiationDoseRate> {
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ import org.openhab.core.library.dimension.ElectricConductivity;
|
|||||||
import org.openhab.core.library.dimension.EmissionIntensity;
|
import org.openhab.core.library.dimension.EmissionIntensity;
|
||||||
import org.openhab.core.library.dimension.Intensity;
|
import org.openhab.core.library.dimension.Intensity;
|
||||||
import org.openhab.core.library.dimension.RadiantExposure;
|
import org.openhab.core.library.dimension.RadiantExposure;
|
||||||
|
import org.openhab.core.library.dimension.RadiationDoseRate;
|
||||||
import org.openhab.core.library.dimension.RadiationSpecificActivity;
|
import org.openhab.core.library.dimension.RadiationSpecificActivity;
|
||||||
import org.openhab.core.library.dimension.VolumetricFlowRate;
|
import org.openhab.core.library.dimension.VolumetricFlowRate;
|
||||||
|
|
||||||
@@ -193,6 +194,8 @@ public final class Units extends CustomUnits {
|
|||||||
|
|
||||||
public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(tech.units.indriya.unit.Units.GRAY);
|
public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(tech.units.indriya.unit.Units.GRAY);
|
||||||
public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(tech.units.indriya.unit.Units.SIEVERT);
|
public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(tech.units.indriya.unit.Units.SIEVERT);
|
||||||
|
public static final Unit<RadiationDoseRate> SIEVERT_PER_HOUR = addUnit(
|
||||||
|
new ProductUnit<>(tech.units.indriya.unit.Units.SIEVERT.divide(tech.units.indriya.unit.Units.HOUR)));
|
||||||
public static final Unit<Speed> MILLIMETRE_PER_HOUR = addUnit(
|
public static final Unit<Speed> MILLIMETRE_PER_HOUR = addUnit(
|
||||||
new TransformedUnit<>("mm/h", tech.units.indriya.unit.Units.KILOMETRE_PER_HOUR,
|
new TransformedUnit<>("mm/h", tech.units.indriya.unit.Units.KILOMETRE_PER_HOUR,
|
||||||
MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.valueOf(1000000))));
|
MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.valueOf(1000000))));
|
||||||
|
|||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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 static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.openhab.core.library.types.QuantityType;
|
||||||
|
import org.openhab.core.types.util.UnitUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@link RadiationDoseRate} dimension.
|
||||||
|
*
|
||||||
|
* @author Bernd Weymann - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class RadiationDoseRateTest {
|
||||||
|
|
||||||
|
public static Stream<Arguments> arguments() {
|
||||||
|
return Stream.of(//
|
||||||
|
Arguments.of(QuantityType.valueOf(60.0 + " Sv/h"), "Sv/d", 24.0), //
|
||||||
|
Arguments.of(QuantityType.valueOf(60.0 + " Sv/h"), "Sv/yr", 8760.0), //
|
||||||
|
Arguments.of(QuantityType.valueOf(60.0 + " Sv/h"), "Sv/min", 1.0 / 60.0), //
|
||||||
|
Arguments.of(QuantityType.valueOf(60.0 + " Sv/h"), "Sv/s", 1.0 / 3600.0), //
|
||||||
|
Arguments.of(QuantityType.valueOf(1.23 + " Sv/h"), "mSv/h", 1000.0), //
|
||||||
|
Arguments.of(QuantityType.valueOf(1.23 + " Sv/h"), "μSv/h", 1000000.0) //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test conversion of radiation dose rate quantities to various target units.
|
||||||
|
*
|
||||||
|
* @param observable QuantityType representing the original radiation dose rate quantity
|
||||||
|
* @param targetUnitSymbol String representing the target unit symbol to convert to
|
||||||
|
* @param factor Double representing the expected conversion factor from the original unit to the target unit
|
||||||
|
*/
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("arguments")
|
||||||
|
public void testConversion(QuantityType<?> observable, String targetUnitSymbol, Double factor) {
|
||||||
|
QuantityType<?> test = observable.toUnit(targetUnitSymbol);
|
||||||
|
assertNotNull(test, "Conversion to target unit failed");
|
||||||
|
assertEquals(observable.getDimension(), test.getDimension(), "Dimension mismatch after conversion");
|
||||||
|
assertEquals(UnitUtils.parseUnit(targetUnitSymbol), test.getUnit(), "Unit symbol mismatch after conversion");
|
||||||
|
assertEquals(observable.doubleValue() * factor, test.doubleValue(), 1 * factor, "Converted value mismatch");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user