diff --git a/bundles/org.openhab.core.model.script/bnd.bnd b/bundles/org.openhab.core.model.script/bnd.bnd index 33108563fe1..dad83d472e7 100644 --- a/bundles/org.openhab.core.model.script/bnd.bnd +++ b/bundles/org.openhab.core.model.script/bnd.bnd @@ -39,6 +39,7 @@ Import-Package: \ org.openhab.core.transform,\ org.openhab.core.transform.actions,\ org.openhab.core.types,\ + org.openhab.core.util,\ org.openhab.core.voice,\ org.openhab.core.voice.text,\ org.openhab.core.io.console,\ 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 new file mode 100644 index 00000000000..5b35a55387c --- /dev/null +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010-2023 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.model.script.actions; + +import org.openhab.core.library.types.HSBType; +import org.openhab.core.library.types.PercentType; +import org.openhab.core.util.ColorUtil; +import org.openhab.core.util.ColorUtil.Gamut; + +/** + * This class provides static methods mapping methods from package org.openhab.core.util + * + * @author Laurent Garnier - Initial contribution + */ +public class CoreUtil { + + public static int[] hsbToRgb(HSBType hsb) { + return ColorUtil.hsbToRgb(hsb); + } + + public static PercentType[] hsbToRgbPercent(HSBType hsb) { + return ColorUtil.hsbToRgbPercent(hsb); + } + + public static int hsbTosRgb(HSBType hsb) { + return ColorUtil.hsbTosRgb(hsb); + } + + public static double[] hsbToXY(HSBType hsb) { + return ColorUtil.hsbToXY(hsb); + } + + public static double[] hsbToXY(HSBType hsb, double[] gamutR, double[] gamutG, double[] gamutB) { + Gamut gamut = new Gamut(gamutR, gamutG, gamutB); + return ColorUtil.hsbToXY(hsb, gamut); + } + + public static HSBType rgbToHsb(int[] rgb) throws IllegalArgumentException { + return ColorUtil.rgbToHsb(rgb); + } + + public static HSBType rgbToHsb(PercentType[] rgb) throws IllegalArgumentException { + return ColorUtil.rgbToHsb(rgb); + } + + public static HSBType xyToHsb(double[] xy) throws IllegalArgumentException { + return ColorUtil.xyToHsb(xy); + } + + public static HSBType xyToHsb(double[] xy, double[] gamutR, double[] gamutG, double[] gamutB) + throws IllegalArgumentException { + Gamut gamut = new Gamut(gamutR, gamutG, gamutB); + return ColorUtil.xyToHsb(xy, gamut); + } +} diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java index 679139df804..b16396532a3 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java @@ -31,6 +31,7 @@ import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; import org.openhab.core.model.script.actions.BusEvent; +import org.openhab.core.model.script.actions.CoreUtil; import org.openhab.core.model.script.actions.Exec; import org.openhab.core.model.script.actions.HTTP; import org.openhab.core.model.script.actions.Log; @@ -100,6 +101,7 @@ protected List> getStaticImportClasses() { result.add(Transformation.class); result.add(ScriptExecution.class); result.add(URLEncoder.class); + result.add(CoreUtil.class); result.add(ImperialUnits.class); result.add(MetricPrefix.class);