use of org.eclipse.smarthome.model.sitemap.Setpoint in project smarthome by eclipse.
the class SetpointRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Setpoint sp = (Setpoint) w;
State state = itemUIRegistry.getState(w);
String newLowerState = state.toString();
String newHigherState = state.toString();
// set defaults for min, max and step
BigDecimal step = sp.getStep();
if (step == null) {
step = BigDecimal.ONE;
}
BigDecimal minValue = sp.getMinValue();
if (minValue == null) {
minValue = BigDecimal.ZERO;
}
BigDecimal maxValue = sp.getMaxValue();
if (maxValue == null) {
maxValue = BigDecimal.valueOf(100);
}
// if the current state is a valid value, we calculate the up and down step values
if (state instanceof DecimalType) {
DecimalType actState = (DecimalType) state;
BigDecimal newLower = actState.toBigDecimal().subtract(step);
BigDecimal newHigher = actState.toBigDecimal().add(step);
if (newLower.compareTo(minValue) < 0) {
newLower = minValue;
}
if (newHigher.compareTo(maxValue) > 0) {
newHigher = maxValue;
}
newLowerState = newLower.toString();
newHigherState = newHigher.toString();
}
String unit = getUnitForWidget(w);
String snippetName = "setpoint";
String snippet = getSnippet(snippetName);
snippet = preprocessSnippet(snippet, w);
snippet = StringUtils.replace(snippet, "%newlowerstate%", newLowerState);
snippet = StringUtils.replace(snippet, "%newhigherstate%", newHigherState);
snippet = StringUtils.replace(snippet, "%value%", getValue(w));
snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString());
snippet = StringUtils.replace(snippet, "%maxValue%", maxValue.toString());
snippet = StringUtils.replace(snippet, "%step%", step.toString());
snippet = StringUtils.replace(snippet, "%unit%", unit);
// Process the color tags
snippet = processColor(w, snippet);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.model.sitemap.Setpoint in project smarthome by eclipse.
the class SetpointRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Setpoint sp = (Setpoint) w;
State state = itemUIRegistry.getState(w);
String newLowerState = state.toString();
String newHigherState = state.toString();
// set defaults for min, max and step
BigDecimal step = sp.getStep();
if (step == null) {
step = BigDecimal.ONE;
}
BigDecimal minValue = sp.getMinValue();
if (minValue == null) {
minValue = BigDecimal.ZERO;
}
BigDecimal maxValue = sp.getMaxValue();
if (maxValue == null) {
maxValue = BigDecimal.valueOf(100);
}
// if the current state is a valid value, we calculate the up and down step values
if (state instanceof DecimalType || state instanceof QuantityType) {
BigDecimal currentState;
if (state instanceof DecimalType) {
currentState = ((DecimalType) state).toBigDecimal();
} else {
currentState = ((QuantityType<?>) state).toBigDecimal();
}
BigDecimal newLower = currentState.subtract(step);
BigDecimal newHigher = currentState.add(step);
if (newLower.compareTo(minValue) < 0) {
newLower = minValue;
}
if (newHigher.compareTo(maxValue) > 0) {
newHigher = maxValue;
}
newLowerState = newLower.toString();
newHigherState = newHigher.toString();
if (state instanceof QuantityType) {
newLowerState = newLowerState + " " + ((QuantityType<?>) state).getUnit().toString();
newHigherState = newHigherState + " " + ((QuantityType<?>) state).getUnit().toString();
}
}
String snippetName = "setpoint";
String snippet = getSnippet(snippetName);
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%category%", getCategory(w));
snippet = StringUtils.replace(snippet, "%item%", w.getItem());
snippet = StringUtils.replace(snippet, "%state%", getState(w));
snippet = StringUtils.replace(snippet, "%newlowerstate%", newLowerState);
snippet = StringUtils.replace(snippet, "%newhigherstate%", newHigherState);
snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
snippet = StringUtils.replace(snippet, "%format%", getFormat());
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString());
snippet = StringUtils.replace(snippet, "%maxValue%", maxValue.toString());
snippet = StringUtils.replace(snippet, "%step%", step.toString());
// Process the color tags
snippet = processColor(w, snippet);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.model.sitemap.Setpoint in project smarthome by eclipse.
the class SitemapResource method createWidgetBean.
private WidgetDTO createWidgetBean(String sitemapName, Widget widget, boolean drillDown, URI uri, String widgetId, Locale locale) {
// Test visibility
if (itemUIRegistry.getVisiblity(widget) == false) {
return null;
}
WidgetDTO bean = new WidgetDTO();
if (widget.getItem() != null) {
try {
Item item = itemUIRegistry.getItem(widget.getItem());
String widgetTypeName = widget.eClass().getInstanceTypeName().substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
boolean isMapview = "mapview".equalsIgnoreCase(widgetTypeName);
Predicate<Item> itemFilter = (i -> i.getType().equals(CoreItemFactory.LOCATION));
bean.item = EnrichedItemDTOMapper.map(item, isMapview, itemFilter, UriBuilder.fromUri(uri).build(), locale);
bean.state = itemUIRegistry.getState(widget).toFullString();
// In case the widget state is identical to the item state, its value is set to null.
if (bean.state != null && bean.state.equals(bean.item.state)) {
bean.state = null;
}
} catch (ItemNotFoundException e) {
logger.debug("{}", e.getMessage());
}
}
bean.widgetId = widgetId;
bean.icon = itemUIRegistry.getCategory(widget);
bean.labelcolor = itemUIRegistry.getLabelColor(widget);
bean.valuecolor = itemUIRegistry.getValueColor(widget);
bean.label = itemUIRegistry.getLabel(widget);
bean.type = widget.eClass().getName();
if (widget instanceof LinkableWidget) {
LinkableWidget linkableWidget = (LinkableWidget) widget;
EList<Widget> children = itemUIRegistry.getChildren(linkableWidget);
if (widget instanceof Frame) {
for (Widget child : children) {
String wID = itemUIRegistry.getWidgetId(child);
WidgetDTO subWidget = createWidgetBean(sitemapName, child, drillDown, uri, wID, locale);
if (subWidget != null) {
bean.widgets.add(subWidget);
}
}
} else if (children.size() > 0) {
String pageName = itemUIRegistry.getWidgetId(linkableWidget);
bean.linkedPage = createPageBean(sitemapName, itemUIRegistry.getLabel(widget), itemUIRegistry.getCategory(widget), pageName, drillDown ? children : null, drillDown, isLeaf(children), uri, locale, false);
}
}
if (widget instanceof Switch) {
Switch switchWidget = (Switch) widget;
for (Mapping mapping : switchWidget.getMappings()) {
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.label = mapping.getLabel();
bean.mappings.add(mappingBean);
}
}
if (widget instanceof Selection) {
Selection selectionWidget = (Selection) widget;
for (Mapping mapping : selectionWidget.getMappings()) {
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.label = mapping.getLabel();
bean.mappings.add(mappingBean);
}
}
if (widget instanceof Slider) {
Slider sliderWidget = (Slider) widget;
bean.sendFrequency = sliderWidget.getFrequency();
bean.switchSupport = sliderWidget.isSwitchEnabled();
}
if (widget instanceof List) {
List listWidget = (List) widget;
bean.separator = listWidget.getSeparator();
}
if (widget instanceof Image) {
bean.url = buildProxyUrl(sitemapName, widget, uri);
Image imageWidget = (Image) widget;
if (imageWidget.getRefresh() > 0) {
bean.refresh = imageWidget.getRefresh();
}
}
if (widget instanceof Video) {
Video videoWidget = (Video) widget;
if (videoWidget.getEncoding() != null) {
bean.encoding = videoWidget.getEncoding();
}
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
bean.url = videoWidget.getUrl();
} else {
bean.url = buildProxyUrl(sitemapName, videoWidget, uri);
}
}
if (widget instanceof Webview) {
Webview webViewWidget = (Webview) widget;
bean.url = webViewWidget.getUrl();
bean.height = webViewWidget.getHeight();
}
if (widget instanceof Mapview) {
Mapview mapViewWidget = (Mapview) widget;
bean.height = mapViewWidget.getHeight();
}
if (widget instanceof Chart) {
Chart chartWidget = (Chart) widget;
bean.service = chartWidget.getService();
bean.period = chartWidget.getPeriod();
bean.legend = chartWidget.getLegend();
if (chartWidget.getRefresh() > 0) {
bean.refresh = chartWidget.getRefresh();
}
}
if (widget instanceof Setpoint) {
Setpoint setpointWidget = (Setpoint) widget;
bean.minValue = setpointWidget.getMinValue();
bean.maxValue = setpointWidget.getMaxValue();
bean.step = setpointWidget.getStep();
}
return bean;
}
Aggregations