mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
[sitemap] Add new color keyword "itemValue" (#3453)
Closes #3429 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
11e29c45f7
commit
52e36a0216
@ -239,9 +239,6 @@ public class PageChangeListener implements StateChangeListener {
|
||||
event.sitemapName = sitemapName;
|
||||
event.pageId = pageId;
|
||||
event.label = itemUIRegistry.getLabel(widget);
|
||||
event.labelcolor = itemUIRegistry.getLabelColor(widget);
|
||||
event.valuecolor = itemUIRegistry.getValueColor(widget);
|
||||
event.iconcolor = itemUIRegistry.getIconColor(widget);
|
||||
event.widgetId = itemUIRegistry.getWidgetId(widget);
|
||||
event.visibility = itemUIRegistry.getVisiblity(widget);
|
||||
event.descriptionChanged = false;
|
||||
@ -249,6 +246,7 @@ public class PageChangeListener implements StateChangeListener {
|
||||
// the widget including its state (in event.item.state)
|
||||
boolean itemBelongsToWidget = widget.getItem() != null && widget.getItem().equals(item.getName());
|
||||
final Item itemToBeSent = itemBelongsToWidget ? item : getItemForWidget(widget);
|
||||
State stateToBeSent = null;
|
||||
if (itemToBeSent != null) {
|
||||
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
||||
.substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
|
||||
@ -257,13 +255,16 @@ public class PageChangeListener implements StateChangeListener {
|
||||
event.item = EnrichedItemDTOMapper.map(itemToBeSent, drillDown, itemFilter, null, null);
|
||||
|
||||
// event.state is an adjustment of the item state to the widget type.
|
||||
final State stateToBeSent = itemBelongsToWidget ? state : itemToBeSent.getState();
|
||||
stateToBeSent = itemBelongsToWidget ? state : itemToBeSent.getState();
|
||||
event.state = itemUIRegistry.convertState(widget, itemToBeSent, stateToBeSent).toFullString();
|
||||
// In case this state is identical to the item state, its value is set to null.
|
||||
if (event.state != null && event.state.equals(event.item.state)) {
|
||||
event.state = null;
|
||||
}
|
||||
}
|
||||
event.labelcolor = SitemapResource.convertItemValueColor(itemUIRegistry.getLabelColor(widget), stateToBeSent);
|
||||
event.valuecolor = SitemapResource.convertItemValueColor(itemUIRegistry.getValueColor(widget), stateToBeSent);
|
||||
event.iconcolor = SitemapResource.convertItemValueColor(itemUIRegistry.getIconColor(widget), stateToBeSent);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ import org.openhab.core.items.Item;
|
||||
import org.openhab.core.items.ItemNotFoundException;
|
||||
import org.openhab.core.items.StateChangeListener;
|
||||
import org.openhab.core.library.CoreItemFactory;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.model.sitemap.SitemapProvider;
|
||||
import org.openhab.core.model.sitemap.sitemap.Chart;
|
||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||
@ -492,9 +493,11 @@ public class SitemapResource
|
||||
}
|
||||
|
||||
WidgetDTO bean = new WidgetDTO();
|
||||
State itemState = null;
|
||||
if (widget.getItem() != null) {
|
||||
try {
|
||||
Item item = itemUIRegistry.getItem(widget.getItem());
|
||||
itemState = item.getState();
|
||||
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
||||
.substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
|
||||
boolean isMapview = "mapview".equalsIgnoreCase(widgetTypeName);
|
||||
@ -512,9 +515,9 @@ public class SitemapResource
|
||||
}
|
||||
bean.widgetId = widgetId;
|
||||
bean.icon = itemUIRegistry.getCategory(widget);
|
||||
bean.labelcolor = itemUIRegistry.getLabelColor(widget);
|
||||
bean.valuecolor = itemUIRegistry.getValueColor(widget);
|
||||
bean.iconcolor = itemUIRegistry.getIconColor(widget);
|
||||
bean.labelcolor = convertItemValueColor(itemUIRegistry.getLabelColor(widget), itemState);
|
||||
bean.valuecolor = convertItemValueColor(itemUIRegistry.getValueColor(widget), itemState);
|
||||
bean.iconcolor = convertItemValueColor(itemUIRegistry.getIconColor(widget), itemState);
|
||||
bean.label = itemUIRegistry.getLabel(widget);
|
||||
bean.type = widget.eClass().getName();
|
||||
bean.visibility = itemUIRegistry.getVisiblity(widget);
|
||||
@ -610,6 +613,16 @@ public class SitemapResource
|
||||
return bean;
|
||||
}
|
||||
|
||||
public static @Nullable String convertItemValueColor(@Nullable String color, @Nullable State itemState) {
|
||||
if ("itemValue".equals(color)) {
|
||||
if (itemState instanceof HSBType hsbState) {
|
||||
return "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private String buildProxyUrl(String sitemapName, Widget widget, URI uri) {
|
||||
String wId = itemUIRegistry.getWidgetId(widget);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
Loading…
Reference in New Issue
Block a user