From aededaecc282c6487f1206f0761e04e955fbc5c7 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Sun, 17 Nov 2024 10:33:19 +0100 Subject: [PATCH] [DSL] Expose ColorUtil methods to DSL rules (#4410) * [DSL] Expose ColorUtil methods to DSL rules * Expose xyToKelvin and kelvinToXY * Add missing throws declaration Signed-off-by: Holger Friedrich --- .../openhab/core/model/script/actions/CoreUtil.java | 12 ++++++++++++ .../main/java/org/openhab/core/util/ColorUtil.java | 4 ++-- 2 files changed, 14 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 50fb23fed..f6fc5eb94 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,16 @@ public class CoreUtil { Gamut gamut = new Gamut(gamutR, gamutG, gamutB); 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); + } + + 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 f62bf4638..1539c27fe 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 @@ -1651,9 +1651,9 @@ public class ColorUtil { * * @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"); }