Skip to content

Commit

Permalink
Fix parsing integer & booleans parameters in UI component based sitem…
Browse files Browse the repository at this point in the history
…aps (openhab#2072)

* Fix parsing integer & booleans parameters in UI component based sitemaps

Also catch remaining exceptions and log a warning/ignore the parameter
instead of making the whole sitemap building process fail.

Fix wrong feature ID for the video widget URL.

Fixes openhab#2047.
Fixes openhab#1987.
Fixes openhab#1898.
Fixes openhab#1875.
Fixes openhab/openhab-webui#745.

Signed-off-by: Yannick Schaus <[email protected]>
  • Loading branch information
ghys authored Jan 5, 2021
1 parent 55d2aaf commit fcaf251
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.core.ui.internal.components;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -178,7 +179,7 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
case "Video":
VideoImpl videoWidget = (VideoImpl) SitemapFactory.eINSTANCE.createVideo();
widget = videoWidget;
setWidgetPropertyFromComponentConfig(widget, component, "url", SitemapPackage.IMAGE__URL);
setWidgetPropertyFromComponentConfig(widget, component, "url", SitemapPackage.VIDEO__URL);
setWidgetPropertyFromComponentConfig(widget, component, "encoding", SitemapPackage.VIDEO__ENCODING);
break;
case "Chart":
Expand Down Expand Up @@ -220,7 +221,6 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) {
SelectionImpl selectionWidget = (SelectionImpl) SitemapFactory.eINSTANCE.createSelection();
addWidgetMappings(selectionWidget.getMappings(), component);
widget = selectionWidget;
setWidgetPropertyFromComponentConfig(widget, component, "height", SitemapPackage.WEBVIEW__HEIGHT);
break;
case "List":
ListImpl listWidget = (ListImpl) SitemapFactory.eINSTANCE.createList();
Expand Down Expand Up @@ -282,8 +282,21 @@ private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UICom
if (value == null) {
return;
}
WidgetImpl widgetImpl = (WidgetImpl) widget;
widgetImpl.eSet(feature, ConfigUtil.normalizeType(value));
try {
WidgetImpl widgetImpl = (WidgetImpl) widget;
Object normalizedValue = ConfigUtil.normalizeType(value);
if (widgetImpl.eGet(feature, false, false) instanceof Integer) {
normalizedValue = (normalizedValue instanceof BigDecimal) ? ((BigDecimal) normalizedValue).intValue()
: Integer.valueOf(normalizedValue.toString());
} else if (widgetImpl.eGet(feature, false, false) instanceof Boolean
&& !(normalizedValue instanceof Boolean)) {
normalizedValue = Boolean.valueOf(normalizedValue.toString());
}
widgetImpl.eSet(feature, normalizedValue);
} catch (Exception e) {
logger.warn("Cannot set {} parameter for {} widget parameter: {}", configParamName, component.getType(),
e.getMessage());
}
}

private void addWidgetMappings(EList<Mapping> mappings, UIComponent component) {
Expand Down

0 comments on commit fcaf251

Please sign in to comment.