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.sitemapName = sitemapName;
|
||||||
event.pageId = pageId;
|
event.pageId = pageId;
|
||||||
event.label = itemUIRegistry.getLabel(widget);
|
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.widgetId = itemUIRegistry.getWidgetId(widget);
|
||||||
event.visibility = itemUIRegistry.getVisiblity(widget);
|
event.visibility = itemUIRegistry.getVisiblity(widget);
|
||||||
event.descriptionChanged = false;
|
event.descriptionChanged = false;
|
||||||
@ -249,6 +246,7 @@ public class PageChangeListener implements StateChangeListener {
|
|||||||
// the widget including its state (in event.item.state)
|
// the widget including its state (in event.item.state)
|
||||||
boolean itemBelongsToWidget = widget.getItem() != null && widget.getItem().equals(item.getName());
|
boolean itemBelongsToWidget = widget.getItem() != null && widget.getItem().equals(item.getName());
|
||||||
final Item itemToBeSent = itemBelongsToWidget ? item : getItemForWidget(widget);
|
final Item itemToBeSent = itemBelongsToWidget ? item : getItemForWidget(widget);
|
||||||
|
State stateToBeSent = null;
|
||||||
if (itemToBeSent != null) {
|
if (itemToBeSent != null) {
|
||||||
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
||||||
.substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
|
.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.item = EnrichedItemDTOMapper.map(itemToBeSent, drillDown, itemFilter, null, null);
|
||||||
|
|
||||||
// event.state is an adjustment of the item state to the widget type.
|
// 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();
|
event.state = itemUIRegistry.convertState(widget, itemToBeSent, stateToBeSent).toFullString();
|
||||||
// In case this state is identical to the item state, its value is set to null.
|
// 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)) {
|
if (event.state != null && event.state.equals(event.item.state)) {
|
||||||
event.state = null;
|
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;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ import org.openhab.core.items.Item;
|
|||||||
import org.openhab.core.items.ItemNotFoundException;
|
import org.openhab.core.items.ItemNotFoundException;
|
||||||
import org.openhab.core.items.StateChangeListener;
|
import org.openhab.core.items.StateChangeListener;
|
||||||
import org.openhab.core.library.CoreItemFactory;
|
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.SitemapProvider;
|
||||||
import org.openhab.core.model.sitemap.sitemap.Chart;
|
import org.openhab.core.model.sitemap.sitemap.Chart;
|
||||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||||
@ -492,9 +493,11 @@ public class SitemapResource
|
|||||||
}
|
}
|
||||||
|
|
||||||
WidgetDTO bean = new WidgetDTO();
|
WidgetDTO bean = new WidgetDTO();
|
||||||
|
State itemState = null;
|
||||||
if (widget.getItem() != null) {
|
if (widget.getItem() != null) {
|
||||||
try {
|
try {
|
||||||
Item item = itemUIRegistry.getItem(widget.getItem());
|
Item item = itemUIRegistry.getItem(widget.getItem());
|
||||||
|
itemState = item.getState();
|
||||||
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
String widgetTypeName = widget.eClass().getInstanceTypeName()
|
||||||
.substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
|
.substring(widget.eClass().getInstanceTypeName().lastIndexOf(".") + 1);
|
||||||
boolean isMapview = "mapview".equalsIgnoreCase(widgetTypeName);
|
boolean isMapview = "mapview".equalsIgnoreCase(widgetTypeName);
|
||||||
@ -512,9 +515,9 @@ public class SitemapResource
|
|||||||
}
|
}
|
||||||
bean.widgetId = widgetId;
|
bean.widgetId = widgetId;
|
||||||
bean.icon = itemUIRegistry.getCategory(widget);
|
bean.icon = itemUIRegistry.getCategory(widget);
|
||||||
bean.labelcolor = itemUIRegistry.getLabelColor(widget);
|
bean.labelcolor = convertItemValueColor(itemUIRegistry.getLabelColor(widget), itemState);
|
||||||
bean.valuecolor = itemUIRegistry.getValueColor(widget);
|
bean.valuecolor = convertItemValueColor(itemUIRegistry.getValueColor(widget), itemState);
|
||||||
bean.iconcolor = itemUIRegistry.getIconColor(widget);
|
bean.iconcolor = convertItemValueColor(itemUIRegistry.getIconColor(widget), itemState);
|
||||||
bean.label = itemUIRegistry.getLabel(widget);
|
bean.label = itemUIRegistry.getLabel(widget);
|
||||||
bean.type = widget.eClass().getName();
|
bean.type = widget.eClass().getName();
|
||||||
bean.visibility = itemUIRegistry.getVisiblity(widget);
|
bean.visibility = itemUIRegistry.getVisiblity(widget);
|
||||||
@ -610,6 +613,16 @@ public class SitemapResource
|
|||||||
return bean;
|
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) {
|
private String buildProxyUrl(String sitemapName, Widget widget, URI uri) {
|
||||||
String wId = itemUIRegistry.getWidgetId(widget);
|
String wId = itemUIRegistry.getWidgetId(widget);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Loading…
Reference in New Issue
Block a user