From c12067a63bf053ff1d71b632ef0ab36c9c1a9faf Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sun, 13 Aug 2023 19:36:41 +0200 Subject: [PATCH] [sitemap] Add new "staticIcon" parameter (#3735) When set, the UI should not provide the item state when requestiong the OH icon and should not request again the icon when the item state is updated. Related to openhab/openhab-android#3404 Signed-off-by: Laurent Garnier --- .../sitemap/internal/SitemapResource.java | 1 + .../io/rest/sitemap/internal/WidgetDTO.java | 1 + .../openhab/core/model/sitemap/Sitemap.xtext | 47 ++++++++++++------- .../UIComponentSitemapProvider.java | 1 + .../ui/internal/items/ItemUIRegistryImpl.java | 3 ++ 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java index 2c92feed0f7..2874f5a7654 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java @@ -523,6 +523,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null } bean.widgetId = widgetId; bean.icon = itemUIRegistry.getCategory(widget); + bean.staticIcon = widget.getStaticIcon() != null; bean.labelcolor = convertItemValueColor(itemUIRegistry.getLabelColor(widget), itemState); bean.valuecolor = convertItemValueColor(itemUIRegistry.getValueColor(widget), itemState); bean.iconcolor = convertItemValueColor(itemUIRegistry.getIconColor(widget), itemState); diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java index c9dc713b082..ce947faadba 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/WidgetDTO.java @@ -35,6 +35,7 @@ public class WidgetDTO { public String label; public String icon; + public Boolean staticIcon; public String labelcolor; public String valuecolor; public String iconcolor; diff --git a/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext b/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext index 101297bf8bf..2a3088db948 100644 --- a/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext +++ b/bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/Sitemap.xtext @@ -24,28 +24,32 @@ LinkableWidget: '}')?; Frame: - {Frame} 'Frame' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + {Frame} 'Frame' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Text: - {Text} 'Text' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + {Text} 'Text' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Group: - 'Group' (('item=' item=GroupItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Group' (('item=' item=GroupItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Image: - 'Image' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Image' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('url=' url=STRING)? & ('refresh=' refresh=INT)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -53,7 +57,8 @@ Image: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Video: - 'Video' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Video' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('url=' url=STRING) & ('encoding=' encoding=STRING)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -61,7 +66,8 @@ Video: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Chart: - 'Chart' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Chart' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('service=' service=STRING)? & ('refresh=' refresh=INT)? & ('period=' period=ID) & ('legend=' legend=BOOLEAN_OBJECT)? & ('forceasitem=' forceAsItem=BOOLEAN_OBJECT)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & @@ -71,7 +77,8 @@ Chart: ('yAxisDecimalPattern=' yAxisDecimalPattern=(STRING))?); Webview: - 'Webview' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Webview' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('height=' height=INT)? & ('url=' url=STRING) & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -79,7 +86,8 @@ Webview: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Switch: - 'Switch' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Switch' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -87,7 +95,8 @@ Switch: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Mapview: - 'Mapview' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Mapview' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('height=' height=INT)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -95,7 +104,8 @@ Mapview: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Slider: - 'Slider' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Slider' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('sendFrequency=' frequency=INT)? & (switchEnabled?='switchSupport')? & ('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & @@ -104,7 +114,8 @@ Slider: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Selection: - 'Selection' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Selection' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -112,7 +123,8 @@ Selection: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Setpoint: - 'Setpoint' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Setpoint' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -120,15 +132,17 @@ Setpoint: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Colorpicker: - 'Colorpicker' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & ('sendFrequency=' - frequency=INT)? & + 'Colorpicker' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & + ('sendFrequency=' frequency=INT)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & ('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? & ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Input: - 'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('inputHint=' inputHint=STRING)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & @@ -136,7 +150,8 @@ Input: ('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?); Default: - 'Default' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & ('icon=' icon=Icon)? & + 'Default' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? & + (('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? & ('height=' height=INT)? & ('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? & ('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? & diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java index a9bee32fd9c..6222e8f7cd9 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java @@ -267,6 +267,7 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { if (widget != null) { setWidgetPropertyFromComponentConfig(widget, component, "label", SitemapPackage.WIDGET__LABEL); setWidgetPropertyFromComponentConfig(widget, component, "icon", SitemapPackage.WIDGET__ICON); + setWidgetPropertyFromComponentConfig(widget, component, "staticIcon", SitemapPackage.WIDGET__STATIC_ICON); setWidgetPropertyFromComponentConfig(widget, component, "item", SitemapPackage.WIDGET__ITEM); if (widget instanceof LinkableWidget linkableWidget) { diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java index 8a96b4b9532..c290fb52640 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java @@ -641,6 +641,8 @@ private String transform(String label, boolean matchTransform, @Nullable String // if an icon is defined for the widget, use it if (w.getIcon() != null) { category = w.getIcon(); + } else if (w.getStaticIcon() != null) { + category = w.getStaticIcon(); } else { // otherwise check if any item ui provider provides an icon for this item String itemName = w.getItem(); @@ -792,6 +794,7 @@ public EList getChildren(LinkableWidget w) { private void copyProperties(Widget source, Widget target) { target.setItem(source.getItem()); target.setIcon(source.getIcon()); + target.setStaticIcon(source.getStaticIcon()); target.setLabel(source.getLabel()); target.getVisibility().addAll(EcoreUtil.copyAll(source.getVisibility())); target.getLabelColor().addAll(EcoreUtil.copyAll(source.getLabelColor()));