From 784ac70f91b1136a21daa0a4da814be512174666 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Mon, 31 Jul 2023 11:54:53 +0200 Subject: [PATCH] [BasicUI] Handle the new parameter "staticIcon" When set on a sitemap element, Basic UI ignores the item state when initially requesting the OH icon and do not request it again when the item state is updated. Depends on openhab/openhab-core#3735 Related to openhab/openhab-android#3404 Signed-off-by: Laurent Garnier --- .../ui/basic/internal/render/AbstractWidgetRenderer.java | 2 +- .../org/openhab/ui/basic/internal/render/ChartRenderer.java | 2 +- .../org/openhab/ui/basic/internal/render/ImageRenderer.java | 2 +- .../org/openhab/ui/basic/internal/render/VideoRenderer.java | 2 +- .../src/main/resources/snippets/icon_oh.html | 2 +- .../src/main/resources/snippets/icon_oh_no_state.html | 2 +- bundles/org.openhab.ui.basic/web-src/smarthome.js | 4 +++- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java index 7134570c0d..3b2d974d70 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java @@ -110,7 +110,7 @@ public ItemUIRegistry getItemUIRegistry() { * @return HTML code */ protected String preprocessSnippet(String originalSnippet, Widget w) { - return preprocessSnippet(originalSnippet, w, false); + return preprocessSnippet(originalSnippet, w, w.isStaticIcon()); } /** diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java index 37a03cc8d4..5901da569c 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java @@ -123,7 +123,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th } String snippet = getSnippet("chart"); - snippet = preprocessSnippet(snippet, w); + snippet = preprocessSnippet(snippet, w, true); if (chart.getRefresh() > 0) { snippet = snippet.replace("%update_interval%", Integer.toString(chart.getRefresh())); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java index e6c691e45a..df9354e060 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java @@ -69,7 +69,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String widgetId = itemUIRegistry.getWidgetId(w); snippet = snippet.replace("%id%", widgetId); - snippet = preprocessSnippet(snippet, w); + snippet = preprocessSnippet(snippet, w, true); boolean validUrl = isValidURL(image.getUrl()); String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId; diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java index ab95955437..98f0ef7ae0 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java @@ -66,7 +66,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th && videoWidget.getEncoding().toLowerCase().contains("mjpeg")) ? "image" : "video"; snippet = getSnippet(snippetName); - snippet = preprocessSnippet(snippet, w); + snippet = preprocessSnippet(snippet, w, true); State state = itemUIRegistry.getState(w); String url; diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh.html index 53b690ab8d..de19af50bb 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh_no_state.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh_no_state.html index 2effa429a4..f568573b32 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh_no_state.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/icon_oh_no_state.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/bundles/org.openhab.ui.basic/web-src/smarthome.js b/bundles/org.openhab.ui.basic/web-src/smarthome.js index 169db5427a..c5e2fd0c91 100644 --- a/bundles/org.openhab.ui.basic/web-src/smarthome.js +++ b/bundles/org.openhab.ui.basic/web-src/smarthome.js @@ -375,6 +375,7 @@ } if (_t.icon !== null) { + _t.staticIcon = _t.icon.getAttribute(o.staticAttribute) === "true"; splittedIconAttr = _t.icon.getAttribute(o.iconAttribute).split(":"); _t.iconSet = splittedIconAttr[0]; _t.iconName = splittedIconAttr[1]; @@ -432,7 +433,7 @@ src; // Some widgets don't have icons - if (_t.icon !== null) { + if (_t.icon !== null && !_t.staticIcon) { if (state.length < 200) { src = "/icon/" + encodeURIComponent(_t.iconName) + "?state=" + encodeURIComponent(state) + @@ -2735,6 +2736,7 @@ idAttribute: "data-widget-id", iconAttribute: "data-icon", iconTypeAttribute: "data-icon-type", + staticAttribute: "data-static", inlineSvgAttribute: "data-inline-svg", primaryColorAttribute: "data-primary-color", secondaryColorAttribute: "data-secondary-color",