From 0c7aa4d07dd4a7636fbad4c5457f0907a22196cc Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sun, 21 Apr 2024 16:29:19 +0200 Subject: [PATCH] [BasicUI] Fix slider behaviour and implement two different modes (#2535) Fix #2525 Also related to openhab/openhab-core#4084 and openhab/openhab-core#3430 Two behaviour modes are now supported. - If releaseOnly parameter is set, the new value is sent to the item only when the slider is released. - If releaseOnly parameter is not set, new values are sent to the item while moving the slider. Events are sent at a certain frequency, this frequency is defined by the sendFrequency parameter if set or every 200 ms by default. Event is not sent when the value is is unchanged (when stopping the move but keeping the mouse pressed). The brightness slider of the colorpicker widget is also updated to send regular new color commands when moving the slider. Signed-off-by: Laurent Garnier --- .../basic/internal/render/SliderRenderer.java | 5 +- .../src/main/resources/snippets/slider.html | 2 +- .../org.openhab.ui.basic/web-src/smarthome.js | 71 ++++++++++++------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java index 8f8d02cadb..dd5316d57b 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java @@ -65,9 +65,6 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String snippetName = "slider"; String snippet = getSnippet(snippetName); - // set the default send-update frequency to 200ms - String frequency = s.getFrequency() == 0 ? "200" : Integer.toString(s.getFrequency()); - String unit = getUnitForWidget(w); if (unit == null) { // Search the unit in the item state @@ -82,7 +79,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th } snippet = preprocessSnippet(snippet, w); - snippet = snippet.replace("%frequency%", frequency); + snippet = snippet.replace("%release_only%", s.isReleaseOnly() ? "true" : "false"); snippet = snippet.replace("%switch%", s.isSwitchEnabled() ? "1" : "0"); snippet = snippet.replace("%unit%", unit == null ? "" : unit); snippet = snippet.replace("%minValue%", minValueOf(s)); diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/slider.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/slider.html index db25da5fe7..e3ffa570f4 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/slider.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/slider.html @@ -21,7 +21,7 @@ data-icon-color="%icon_color%" >