From 73171b6695fb1ce5e5c1748b14eb6f336304f381 Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Tue, 29 Oct 2024 16:01:17 +0000 Subject: [PATCH 1/4] [Units] add unit alias for Micro Reciprocal Kelvin Signed-off-by: AndrewFG --- .../src/main/java/org/openhab/core/library/unit/Units.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java index 824d531f801..1723d4f6624 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java @@ -319,6 +319,9 @@ public final class Units extends CustomUnits { SimpleUnitFormat.getInstance().alias(MONTH, "mo"); SimpleUnitFormat.getInstance().alias(WEEK, "wk"); SimpleUnitFormat.getInstance().alias(YEAR, "y"); + + // other aliases + SimpleUnitFormat.getInstance().alias(MIRED, "MK⁻¹"); } private Units() { From 9bce2b2ed14b9ccb2d601be935bf0e531547fc94 Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Tue, 29 Oct 2024 23:26:55 +0000 Subject: [PATCH 2/4] adopt reviewer suggestion Signed-off-by: AndrewFG --- .../src/main/java/org/openhab/core/library/unit/Units.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java index 1723d4f6624..57660a4c5a0 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java @@ -293,7 +293,7 @@ public final class Units extends CustomUnits { SimpleUnitFormat.getInstance().label(MILLIAMPERE_HOUR, "mAh"); SimpleUnitFormat.getInstance().label(MILLIBAR, "mbar"); SimpleUnitFormat.getInstance().label(MILLIMETRE_OF_MERCURY, MILLIMETRE_OF_MERCURY.getSymbol()); - SimpleUnitFormat.getInstance().label(MIRED, "mired"); + SimpleUnitFormat.getInstance().label(MIRED, "MK⁻¹"); SimpleUnitFormat.getInstance().label(PARTS_PER_BILLION, "ppb"); SimpleUnitFormat.getInstance().label(PARTS_PER_MILLION, "ppm"); SimpleUnitFormat.getInstance().label(PETABYTE, "PB"); @@ -321,7 +321,8 @@ public final class Units extends CustomUnits { SimpleUnitFormat.getInstance().alias(YEAR, "y"); // other aliases - SimpleUnitFormat.getInstance().alias(MIRED, "MK⁻¹"); + SimpleUnitFormat.getInstance().alias(MIRED, "mired"); + SimpleUnitFormat.getInstance().alias(MIRED, "mirek"); } private Units() { From ef3e58f3a64f172c5029046a247ca39d16f14fd6 Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Fri, 1 Nov 2024 00:02:18 +0000 Subject: [PATCH 3/4] adopt reviewer suggestion Signed-off-by: AndrewFG --- .../src/main/java/org/openhab/core/library/unit/Units.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java index 57660a4c5a0..f3e220fb152 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java @@ -294,6 +294,8 @@ public final class Units extends CustomUnits { SimpleUnitFormat.getInstance().label(MILLIBAR, "mbar"); SimpleUnitFormat.getInstance().label(MILLIMETRE_OF_MERCURY, MILLIMETRE_OF_MERCURY.getSymbol()); SimpleUnitFormat.getInstance().label(MIRED, "MK⁻¹"); + SimpleUnitFormat.getInstance().alias(MIRED, "mired"); + SimpleUnitFormat.getInstance().alias(MIRED, "mirek"); SimpleUnitFormat.getInstance().label(PARTS_PER_BILLION, "ppb"); SimpleUnitFormat.getInstance().label(PARTS_PER_MILLION, "ppm"); SimpleUnitFormat.getInstance().label(PETABYTE, "PB"); @@ -319,10 +321,6 @@ public final class Units extends CustomUnits { SimpleUnitFormat.getInstance().alias(MONTH, "mo"); SimpleUnitFormat.getInstance().alias(WEEK, "wk"); SimpleUnitFormat.getInstance().alias(YEAR, "y"); - - // other aliases - SimpleUnitFormat.getInstance().alias(MIRED, "mired"); - SimpleUnitFormat.getInstance().alias(MIRED, "mirek"); } private Units() { From c27c5181e4b5e078894ff840ca2d22f6d164f7db Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Fri, 1 Nov 2024 10:26:49 +0000 Subject: [PATCH 4/4] add junit test Signed-off-by: AndrewFG --- .../java/org/openhab/core/library/unit/UnitsTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/UnitsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/UnitsTest.java index 74ef456bb01..f88cb2a6bb5 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/UnitsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/UnitsTest.java @@ -431,6 +431,17 @@ public void testYearMonthDay() { assertThat(converted2.doubleValue(), is(closeTo(12.0, DEFAULT_ERROR))); } + @Test + public void testColorTemperatureAliases() { + QuantityType value; + value = QuantityType.valueOf("20 mired"); + assertEquals(Units.MIRED, value.getUnit()); + value = QuantityType.valueOf("20 mirek"); + assertEquals(Units.MIRED, value.getUnit()); + value = QuantityType.valueOf("20 MK⁻¹"); + assertEquals(Units.MIRED, value.getUnit()); + } + private static class QuantityEquals extends IsEqual> { private Quantity quantity;