Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sitemap] Add new color keyword "itemValue" #3453

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,14 @@ private SitemapWidgetEvent constructSitemapEventForWidget(Item item, State state
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;
// event.item contains the (potentially changed) data of the item belonging to
// 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);
Expand All @@ -257,13 +255,16 @@ private SitemapWidgetEvent constructSitemapEventForWidget(Item item, State state
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
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;
Expand Down Expand Up @@ -492,9 +493,11 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
}

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);
Expand All @@ -512,9 +515,9 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
}
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);
Expand Down Expand Up @@ -610,6 +613,16 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
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();
Expand Down