From 718d694f2834d55d0ff40168b1f05faab74a400c Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Mon, 7 Oct 2024 18:23:17 +0200 Subject: [PATCH 1/2] [DSL] Expose ColorUtil methods to DSL rules * Expose xyToKelvin and kelvinToXY * Add missing throws declaration Signed-off-by: Holger Friedrich --- .../org/openhab/core/model/script/actions/CoreUtil.java | 8 ++++++++ .../src/main/java/org/openhab/core/util/ColorUtil.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java index 50fb23fed5d..b30219e12d1 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java @@ -70,4 +70,12 @@ public static HSBType xyToHsb(double[] xy, double[] gamutR, double[] gamutG, dou Gamut gamut = new Gamut(gamutR, gamutG, gamutB); return ColorUtil.xyToHsb(xy, gamut); } + + public static double[] kelvinToXY(double kelvin) throws IndexOutOfBoundsException { + return ColorUtil.kelvinToXY(kelvin); + } + + public static double xyToKelvin(double[] xy) throws IllegalArgumentException { + return ColorUtil.xyToKelvin(xy); + } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java index d7b1499e3c4..a611ece5767 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java @@ -1202,9 +1202,9 @@ public static double[] kelvinToXY(double kelvin) throws IndexOutOfBoundsExceptio * * @param xy an array with the CIE colour XY values to be converted * @return the colour temperature in K - * @throws IndexOutOfBoundsException if the wrong number of arguments is provided + * @throws IllegalArgumentException if the wrong number of arguments is provided */ - public static double xyToKelvin(double[] xy) { + public static double xyToKelvin(double[] xy) throws IllegalArgumentException { if (xy.length != 2) { throw new IllegalArgumentException("xyToKelvin() requires 2 arguments"); } From 96ae0df4506aa4c4dd76700f469818ba1a3e3885 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Tue, 8 Oct 2024 01:00:38 +0200 Subject: [PATCH 2/2] * Expose xyToDuv Signed-off-by: Holger Friedrich --- .../src/org/openhab/core/model/script/actions/CoreUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java index b30219e12d1..f6fc5eb9416 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java @@ -71,6 +71,10 @@ public static HSBType xyToHsb(double[] xy, double[] gamutR, double[] gamutG, dou return ColorUtil.xyToHsb(xy, gamut); } + public static double xyToDuv(double[] xy) throws IllegalArgumentException { + return ColorUtil.xyToDuv(xy); + } + public static double[] kelvinToXY(double kelvin) throws IndexOutOfBoundsException { return ColorUtil.kelvinToXY(kelvin); }