From 7619db475266dd533908ac1e954d3fa8ad16ae1c Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sat, 9 Sep 2023 13:30:57 +0200 Subject: [PATCH] [BasicUI] Handle the new parameter "staticIcon" (#1998) 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 | 3 ++- .../src/main/resources/snippets/buttons.html | 1 + .../src/main/resources/snippets/colorpicker.html | 1 + .../src/main/resources/snippets/group.html | 1 + .../src/main/resources/snippets/input.html | 1 + .../src/main/resources/snippets/mapview.html | 1 + .../src/main/resources/snippets/rollerblind.html | 1 + .../src/main/resources/snippets/selection.html | 1 + .../src/main/resources/snippets/setpoint.html | 1 + .../src/main/resources/snippets/slider.html | 1 + .../src/main/resources/snippets/switch.html | 1 + .../src/main/resources/snippets/text.html | 1 + .../src/main/resources/snippets/text_link.html | 1 + bundles/org.openhab.ui.basic/web-src/smarthome.js | 4 +++- 14 files changed, 17 insertions(+), 2 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 ce09d970ab..3815f99069 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 @@ -111,7 +111,7 @@ public ItemUIRegistry getItemUIRegistry() { * @return HTML code */ protected String preprocessSnippet(String originalSnippet, Widget w) { - return preprocessSnippet(originalSnippet, w, false); + return preprocessSnippet(originalSnippet, w, w.getStaticIcon() != null); } /** @@ -128,6 +128,7 @@ protected String preprocessSnippet(String originalSnippet, Widget w, boolean ign snippet = snippet.replace("%cells%", String.valueOf(12 / config.getNbColsDesktop())); snippet = snippet.replace("%cells_tablet%", String.valueOf(8 / config.getNbColsTablet())); snippet = snippet.replace("%widget_id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%icon_with_state%", Boolean.valueOf(!ignoreStateForIcon).toString()); snippet = snippet.replace("%item%", w.getItem() != null ? w.getItem() : ""); // Optimization: avoid calling 3 times itemUIRegistry.getLabel(w) String text = itemUIRegistry.getLabel(w); diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html index 8ad90b5fd9..198a56e386 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html @@ -15,6 +15,7 @@ data-has-value="%has_value%" data-count="%count%" data-widget-id="%widget_id%" + data-icon-with-state="%icon_with_state%" > %buttons% diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html index d0af3637ff..767ef95fd8 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html @@ -11,6 +11,7 @@ data-item="%item%" data-value="%state%" data-widget-id="%widget_id%" + data-icon-with-state="%icon_with_state%" >