[Sitemap] Add support for multiple AND conditions (#3819)
Concerns labelcolor, valuecolor and visibility Also fix wrong positions of ")" in Sitemap.xtext Closes #3058 Signed-off-by: Laurent Garnier <lg.hc@free.fr>pull/3820/head^2
parent
eff85c6470
commit
e5518b9322
|
@ -23,6 +23,7 @@ import java.util.function.Predicate;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.openhab.core.events.Event;
|
||||
import org.openhab.core.events.EventSubscriber;
|
||||
|
@ -36,6 +37,7 @@ import org.openhab.core.items.events.ItemStateChangedEvent;
|
|||
import org.openhab.core.library.CoreItemFactory;
|
||||
import org.openhab.core.model.sitemap.sitemap.Chart;
|
||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||
import org.openhab.core.model.sitemap.sitemap.Condition;
|
||||
import org.openhab.core.model.sitemap.sitemap.Frame;
|
||||
import org.openhab.core.model.sitemap.sitemap.VisibilityRule;
|
||||
import org.openhab.core.model.sitemap.sitemap.Widget;
|
||||
|
@ -47,6 +49,7 @@ import org.openhab.core.ui.items.ItemUIRegistry;
|
|||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
* @author Laurent Garnier - Added support for icon color
|
||||
* @author Laurent Garnier - Support added for multiple AND conditions in labelcolor/valuecolor/visibility
|
||||
*/
|
||||
public class PageChangeListener implements EventSubscriber {
|
||||
|
||||
|
@ -121,25 +124,33 @@ public class PageChangeListener implements EventSubscriber {
|
|||
}
|
||||
// now scan visibility rules
|
||||
for (VisibilityRule rule : widget.getVisibility()) {
|
||||
addItemWithName(items, rule.getItem());
|
||||
addItemsFromConditions(items, rule.getConditions());
|
||||
}
|
||||
// now scan label color rules
|
||||
for (ColorArray rule : widget.getLabelColor()) {
|
||||
addItemWithName(items, rule.getItem());
|
||||
addItemsFromConditions(items, rule.getConditions());
|
||||
}
|
||||
// now scan value color rules
|
||||
for (ColorArray rule : widget.getValueColor()) {
|
||||
addItemWithName(items, rule.getItem());
|
||||
addItemsFromConditions(items, rule.getConditions());
|
||||
}
|
||||
// now scan value icon rules
|
||||
// now scan icon color rules
|
||||
for (ColorArray rule : widget.getIconColor()) {
|
||||
addItemWithName(items, rule.getItem());
|
||||
addItemsFromConditions(items, rule.getConditions());
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void addItemsFromConditions(Set<Item> items, @Nullable EList<Condition> conditions) {
|
||||
if (conditions != null) {
|
||||
for (Condition condition : conditions) {
|
||||
addItemWithName(items, condition.getItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addItemWithName(Set<Item> items, String itemName) {
|
||||
if (itemName != null) {
|
||||
try {
|
||||
|
@ -238,10 +249,14 @@ public class PageChangeListener implements EventSubscriber {
|
|||
}
|
||||
|
||||
private boolean definesVisibilityOrColor(Widget w, String name) {
|
||||
return w.getVisibility().stream().anyMatch(r -> name.equals(r.getItem()))
|
||||
|| w.getLabelColor().stream().anyMatch(r -> name.equals(r.getItem()))
|
||||
|| w.getValueColor().stream().anyMatch(r -> name.equals(r.getItem()))
|
||||
|| w.getIconColor().stream().anyMatch(r -> name.equals(r.getItem()));
|
||||
return w.getVisibility().stream().anyMatch(r -> conditionsDependsOnItem(r.getConditions(), name))
|
||||
|| w.getLabelColor().stream().anyMatch(r -> conditionsDependsOnItem(r.getConditions(), name))
|
||||
|| w.getValueColor().stream().anyMatch(r -> conditionsDependsOnItem(r.getConditions(), name))
|
||||
|| w.getIconColor().stream().anyMatch(r -> conditionsDependsOnItem(r.getConditions(), name));
|
||||
}
|
||||
|
||||
private boolean conditionsDependsOnItem(@Nullable EList<Condition> conditions, String name) {
|
||||
return conditions != null && conditions.stream().anyMatch(c -> name.equals(c.getItem()));
|
||||
}
|
||||
|
||||
public void sitemapContentChanged(EList<Widget> widgets) {
|
||||
|
|
|
@ -80,6 +80,7 @@ import org.openhab.core.model.sitemap.sitemap.Button;
|
|||
import org.openhab.core.model.sitemap.sitemap.Buttongrid;
|
||||
import org.openhab.core.model.sitemap.sitemap.Chart;
|
||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||
import org.openhab.core.model.sitemap.sitemap.Condition;
|
||||
import org.openhab.core.model.sitemap.sitemap.Frame;
|
||||
import org.openhab.core.model.sitemap.sitemap.Image;
|
||||
import org.openhab.core.model.sitemap.sitemap.Input;
|
||||
|
@ -135,6 +136,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
* @author Mark Herwege - Added pattern and unit fields
|
||||
* @author Laurent Garnier - Added support for new sitemap element Buttongrid
|
||||
* @author Laurent Garnier - Added icon field for mappings used for switch element
|
||||
* @author Laurent Garnier - Support added for multiple AND conditions in labelcolor/valuecolor/visibility
|
||||
*/
|
||||
@Component(service = { RESTResource.class, EventSubscriber.class })
|
||||
@JaxrsResource
|
||||
|
@ -769,37 +771,35 @@ public class SitemapResource
|
|||
private Set<GenericItem> getItemsInVisibilityCond(EList<VisibilityRule> ruleList) {
|
||||
Set<GenericItem> items = new HashSet<>();
|
||||
for (VisibilityRule rule : ruleList) {
|
||||
String itemName = rule.getItem();
|
||||
if (itemName != null) {
|
||||
try {
|
||||
Item item = itemUIRegistry.getItem(itemName);
|
||||
if (item instanceof GenericItem genericItem) {
|
||||
items.add(genericItem);
|
||||
}
|
||||
} catch (ItemNotFoundException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
getItemsInConditions(rule.getConditions(), items);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private Set<GenericItem> getItemsInColorCond(EList<ColorArray> colorList) {
|
||||
Set<GenericItem> items = new HashSet<>();
|
||||
for (ColorArray color : colorList) {
|
||||
String itemName = color.getItem();
|
||||
if (itemName != null) {
|
||||
try {
|
||||
Item item = itemUIRegistry.getItem(itemName);
|
||||
if (item instanceof GenericItem genericItem) {
|
||||
items.add(genericItem);
|
||||
for (ColorArray rule : colorList) {
|
||||
getItemsInConditions(rule.getConditions(), items);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void getItemsInConditions(@Nullable EList<Condition> conditions, Set<GenericItem> items) {
|
||||
if (conditions != null) {
|
||||
for (Condition condition : conditions) {
|
||||
String itemName = condition.getItem();
|
||||
if (itemName != null) {
|
||||
try {
|
||||
Item item = itemUIRegistry.getItem(itemName);
|
||||
if (item instanceof GenericItem genericItem) {
|
||||
items.add(genericItem);
|
||||
}
|
||||
} catch (ItemNotFoundException e) {
|
||||
// ignore
|
||||
}
|
||||
} catch (ItemNotFoundException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.openhab.core.library.types.OnOffType;
|
|||
import org.openhab.core.library.types.PercentType;
|
||||
import org.openhab.core.model.sitemap.SitemapProvider;
|
||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||
import org.openhab.core.model.sitemap.sitemap.Condition;
|
||||
import org.openhab.core.model.sitemap.sitemap.Sitemap;
|
||||
import org.openhab.core.model.sitemap.sitemap.VisibilityRule;
|
||||
import org.openhab.core.model.sitemap.sitemap.Widget;
|
||||
|
@ -251,6 +252,30 @@ public class SitemapResourceTest extends JavaTest {
|
|||
// return
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenLongPollingShouldObserveItemsFromIconColorConditions() {
|
||||
ItemEvent itemEvent = mock(ItemEvent.class);
|
||||
when(itemEvent.getItemName()).thenReturn(iconColorItem.getName());
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(STATE_UPDATE_WAIT_TIME); // wait for the #getPageData call and listeners to attach to the
|
||||
// item
|
||||
sitemapResource.receive(itemEvent);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}).start();
|
||||
|
||||
// non-null is sufficient here.
|
||||
when(headersMock.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(List.of());
|
||||
|
||||
Response response = sitemapResource.getPageData(headersMock, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null,
|
||||
false);
|
||||
|
||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
||||
assertThat(pageDTO.timeout, is(false)); // assert that the item state change did trigger the blocking method to
|
||||
// return
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetPageDataShouldReturnPageBean() throws ItemNotFoundException {
|
||||
item.setState(new PercentType(50));
|
||||
|
@ -333,28 +358,44 @@ public class SitemapResourceTest extends JavaTest {
|
|||
|
||||
// add visibility rules to the mock widget:
|
||||
VisibilityRule visibilityRule = mock(VisibilityRule.class);
|
||||
when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
|
||||
BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
|
||||
EList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
when(visibilityRule.getConditions()).thenReturn(conditions);
|
||||
EList<VisibilityRule> visibilityRules = new BasicEList<>(1);
|
||||
visibilityRules.add(visibilityRule);
|
||||
when(w1.getVisibility()).thenReturn(visibilityRules);
|
||||
|
||||
// add label color conditions to the item:
|
||||
ColorArray labelColor = mock(ColorArray.class);
|
||||
when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
|
||||
Condition conditon1 = mock(Condition.class);
|
||||
when(conditon1.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
|
||||
EList<Condition> conditions1 = new BasicEList<>();
|
||||
conditions1.add(conditon1);
|
||||
when(labelColor.getConditions()).thenReturn(conditions1);
|
||||
EList<ColorArray> labelColors = new BasicEList<>();
|
||||
labelColors.add(labelColor);
|
||||
when(w1.getLabelColor()).thenReturn(labelColors);
|
||||
|
||||
// add value color conditions to the item:
|
||||
ColorArray valueColor = mock(ColorArray.class);
|
||||
when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
|
||||
Condition conditon2 = mock(Condition.class);
|
||||
when(conditon2.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
|
||||
EList<Condition> conditions2 = new BasicEList<>();
|
||||
conditions2.add(conditon2);
|
||||
when(valueColor.getConditions()).thenReturn(conditions2);
|
||||
EList<ColorArray> valueColors = new BasicEList<>();
|
||||
valueColors.add(valueColor);
|
||||
when(w1.getValueColor()).thenReturn(valueColors);
|
||||
|
||||
// add icon color conditions to the item:
|
||||
ColorArray iconColor = mock(ColorArray.class);
|
||||
when(iconColor.getItem()).thenReturn(ICON_COLOR_ITEM_NAME);
|
||||
Condition conditon3 = mock(Condition.class);
|
||||
when(conditon3.getItem()).thenReturn(ICON_COLOR_ITEM_NAME);
|
||||
EList<Condition> conditions3 = new BasicEList<>();
|
||||
conditions3.add(conditon3);
|
||||
when(iconColor.getConditions()).thenReturn(conditions3);
|
||||
EList<ColorArray> iconColors = new BasicEList<>();
|
||||
iconColors.add(iconColor);
|
||||
when(w1.getIconColor()).thenReturn(iconColors);
|
||||
|
@ -376,7 +417,7 @@ public class SitemapResourceTest extends JavaTest {
|
|||
when(w2.getValueColor()).thenReturn(valueColors);
|
||||
when(w2.getIconColor()).thenReturn(iconColors);
|
||||
|
||||
BasicEList<Widget> widgets = new BasicEList<>(2);
|
||||
EList<Widget> widgets = new BasicEList<>(2);
|
||||
widgets.add(w1);
|
||||
widgets.add(w2);
|
||||
return widgets;
|
||||
|
|
|
@ -26,147 +26,147 @@ LinkableWidget:
|
|||
Frame:
|
||||
{Frame} 'Frame' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Text:
|
||||
{Text} 'Text' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Group:
|
||||
'Group' (('item=' item=GroupItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Image:
|
||||
'Image' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('url=' url=STRING)? & ('refresh=' refresh=INT)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Video:
|
||||
'Video' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('url=' url=STRING) & ('encoding=' encoding=STRING)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Chart:
|
||||
'Chart' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('service=' service=STRING)? & ('refresh=' refresh=INT)? & ('period=' period=ID) &
|
||||
('legend=' legend=BOOLEAN_OBJECT)? & ('forceasitem=' forceAsItem=BOOLEAN_OBJECT)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')? &
|
||||
('yAxisDecimalPattern=' yAxisDecimalPattern=(STRING))?);
|
||||
|
||||
Webview:
|
||||
'Webview' (('item=' item=ItemRef)? & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('height=' height=INT)? & ('url=' url=STRING) &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Switch:
|
||||
'Switch' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Mapview:
|
||||
'Mapview' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('height=' height=INT)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Slider:
|
||||
'Slider' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('sendFrequency=' frequency=INT)? & (switchEnabled?='switchSupport')? &
|
||||
('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Selection:
|
||||
'Selection' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('mappings=[' mappings+=Mapping (',' mappings+=Mapping)* ']')? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Setpoint:
|
||||
'Setpoint' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('minValue=' minValue=Number)? & ('maxValue=' maxValue=Number)? & ('step=' step=Number)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Colorpicker:
|
||||
'Colorpicker' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('sendFrequency=' frequency=INT)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Input:
|
||||
'Input' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('inputHint=' inputHint=STRING)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Buttongrid:
|
||||
'Buttongrid' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('columns=' columns=INT) &
|
||||
('buttons=[' buttons+=Button (',' buttons+=Button)* ']') &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Default:
|
||||
'Default' (('item=' item=ItemRef) & ('label=' label=(ID | STRING))? &
|
||||
(('icon=' icon=Icon) | ('staticIcon=' staticIcon=Icon))? &
|
||||
('height=' height=INT)? &
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)* ']'))? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)* ']'))? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)* ']'))? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)* ']'))?);
|
||||
('labelcolor=[' (LabelColor+=ColorArray (',' LabelColor+=ColorArray)*) ']')? &
|
||||
('valuecolor=[' (ValueColor+=ColorArray (',' ValueColor+=ColorArray)*) ']')? &
|
||||
('iconcolor=[' (IconColor+=ColorArray (',' IconColor+=ColorArray)*) ']')? &
|
||||
('visibility=[' (Visibility+=VisibilityRule (',' Visibility+=VisibilityRule)*) ']')?);
|
||||
|
||||
Button:
|
||||
position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
|
||||
|
@ -175,7 +175,7 @@ Mapping:
|
|||
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
|
||||
|
||||
VisibilityRule:
|
||||
(item=ID) (condition=('==' | '>' | '<' | '>=' | '<=' | '!=')) (sign=('-' | '+'))? (state=XState);
|
||||
conditions+=Condition ('AND' conditions+=Condition)*;
|
||||
|
||||
ItemRef:
|
||||
ID;
|
||||
|
@ -191,8 +191,10 @@ IconName:
|
|||
(ID '-')* ID;
|
||||
|
||||
ColorArray:
|
||||
((item=ID)? (condition=('==' | '>' | '<' | '>=' | '<=' | '!='))? (sign=('-' | '+'))? (state=XState) '=')?
|
||||
(arg=STRING);
|
||||
((conditions+=Condition ('AND' conditions+=Condition)*) '=')? (arg=STRING);
|
||||
|
||||
Condition:
|
||||
(item=ID)? (condition=('==' | '>' | '<' | '>=' | '<=' | '!='))? (sign=('-' | '+'))? (state=XState);
|
||||
|
||||
Command returns ecore::EString:
|
||||
Number | ID | STRING;
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.openhab.core.model.sitemap.sitemap.impl.ButtongridImpl;
|
|||
import org.openhab.core.model.sitemap.sitemap.impl.ChartImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.ColorArrayImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.ColorpickerImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.ConditionImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.DefaultImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.FrameImpl;
|
||||
import org.openhab.core.model.sitemap.sitemap.impl.GroupImpl;
|
||||
|
@ -378,10 +379,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
|||
if (matcher.matches()) {
|
||||
VisibilityRuleImpl visibilityRule = (VisibilityRuleImpl) SitemapFactory.eINSTANCE
|
||||
.createVisibilityRule();
|
||||
visibilityRule.setItem(matcher.group("item"));
|
||||
visibilityRule.setCondition(matcher.group("condition"));
|
||||
visibilityRule.setSign(matcher.group("sign"));
|
||||
visibilityRule.setState(matcher.group("state"));
|
||||
ConditionImpl condition = (ConditionImpl) SitemapFactory.eINSTANCE.createCondition();
|
||||
condition.setItem(matcher.group("item"));
|
||||
condition.setCondition(matcher.group("condition"));
|
||||
condition.setSign(matcher.group("sign"));
|
||||
condition.setState(matcher.group("state"));
|
||||
visibilityRule.eSet(SitemapPackage.VISIBILITY_RULE__CONDITIONS, condition);
|
||||
visibility.add(visibilityRule);
|
||||
} else {
|
||||
logger.warn("Syntax error in visibility rule '{}' for widget {}", sourceVisibility,
|
||||
|
@ -411,11 +414,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
|
|||
Matcher matcher = COLOR_PATTERN.matcher(sourceColor.toString());
|
||||
if (matcher.matches()) {
|
||||
ColorArrayImpl colorArray = (ColorArrayImpl) SitemapFactory.eINSTANCE.createColorArray();
|
||||
colorArray.setItem(matcher.group("item"));
|
||||
colorArray.setCondition(matcher.group("condition"));
|
||||
colorArray.setSign(matcher.group("sign"));
|
||||
colorArray.setState(matcher.group("state"));
|
||||
colorArray.setArg(matcher.group("arg"));
|
||||
ConditionImpl condition = (ConditionImpl) SitemapFactory.eINSTANCE.createCondition();
|
||||
condition.setItem(matcher.group("item"));
|
||||
condition.setCondition(matcher.group("condition"));
|
||||
condition.setSign(matcher.group("sign"));
|
||||
condition.setState(matcher.group("state"));
|
||||
colorArray.eSet(SitemapPackage.COLOR_ARRAY__CONDITIONS, condition);
|
||||
color.add(colorArray);
|
||||
} else {
|
||||
logger.warn("Syntax error in {} rule '{}' for widget {}", key, sourceColor,
|
||||
|
|
|
@ -109,6 +109,7 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
|
||||
* @author Laurent Garnier - new method getIconColor
|
||||
* @author Mark Herwege - new method getFormatPattern(widget), clean pattern
|
||||
* @author Laurent Garnier - Support added for multiple AND conditions in labelcolor/valuecolor/visibility
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, configurationPid = "org.openhab.sitemap", //
|
||||
|
@ -1149,152 +1150,120 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
|||
return matched;
|
||||
}
|
||||
|
||||
private @Nullable String processColorDefinition(@Nullable State state, @Nullable List<ColorArray> colorList) {
|
||||
private @Nullable String processColorDefinition(Widget w, @Nullable List<ColorArray> colorList, String colorType) {
|
||||
// Sanity check
|
||||
if (colorList == null) {
|
||||
return null;
|
||||
}
|
||||
if (colorList.isEmpty()) {
|
||||
if (colorList == null || colorList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.debug("Checking {} color for widget '{}'.", colorType, w.getLabel());
|
||||
|
||||
String colorString = null;
|
||||
|
||||
// Check for the "arg". If it doesn't exist, assume there's just an
|
||||
// static colour
|
||||
if (colorList.size() == 1 && colorList.get(0).getState() == null) {
|
||||
colorString = colorList.get(0).getArg();
|
||||
} else {
|
||||
// Loop through all elements looking for the definition associated
|
||||
// with the supplied value
|
||||
for (ColorArray color : colorList) {
|
||||
// Use a local state variable in case it gets overridden below
|
||||
State cmpState = state;
|
||||
|
||||
if (color.getState() == null) {
|
||||
// If no state associated to the condition, we consider the condition as fulfilled.
|
||||
// It allows defining a default color as last condition in particular.
|
||||
colorString = color.getArg();
|
||||
break;
|
||||
}
|
||||
|
||||
// If there's an item defined here, get its state
|
||||
String itemName = color.getItem();
|
||||
if (itemName != null) {
|
||||
// Try and find the item to test.
|
||||
// If it's not found, return visible
|
||||
Item item;
|
||||
try {
|
||||
item = itemRegistry.getItem(itemName);
|
||||
|
||||
// Get the item state
|
||||
cmpState = item.getState();
|
||||
} catch (ItemNotFoundException e) {
|
||||
logger.warn("Cannot retrieve color item {} for widget", color.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the sign
|
||||
String value;
|
||||
if (color.getSign() != null) {
|
||||
value = color.getSign() + color.getState();
|
||||
} else {
|
||||
value = color.getState();
|
||||
}
|
||||
|
||||
if (cmpState != null && matchStateToValue(cmpState, value, color.getCondition())) {
|
||||
// We have the color for this value - break!
|
||||
colorString = color.getArg();
|
||||
break;
|
||||
}
|
||||
// Loop through all elements looking for the definition associated
|
||||
// with the supplied value
|
||||
for (ColorArray rule : colorList) {
|
||||
if (allConditionsOk(rule.getConditions(), w)) {
|
||||
// We have the color for this value - break!
|
||||
colorString = rule.getArg();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove quotes off the colour - if they exist
|
||||
if (colorString == null) {
|
||||
logger.debug("No {} color found for widget '{}'.", colorType, w.getLabel());
|
||||
return null;
|
||||
}
|
||||
|
||||
// Remove quotes off the colour - if they exist
|
||||
if (colorString.startsWith("\"") && colorString.endsWith("\"")) {
|
||||
colorString = colorString.substring(1, colorString.length() - 1);
|
||||
}
|
||||
logger.debug("{} color for widget '{}' is '{}'.", colorType, w.getLabel(), colorString);
|
||||
|
||||
return colorString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getLabelColor(Widget w) {
|
||||
return processColorDefinition(getState(w), w.getLabelColor());
|
||||
return processColorDefinition(w, w.getLabelColor(), "label");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getValueColor(Widget w) {
|
||||
return processColorDefinition(getState(w), w.getValueColor());
|
||||
return processColorDefinition(w, w.getValueColor(), "value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getIconColor(Widget w) {
|
||||
return processColorDefinition(getState(w), w.getIconColor());
|
||||
return processColorDefinition(w, w.getIconColor(), "icon");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVisiblity(Widget w) {
|
||||
// Default to visible if parameters not set
|
||||
List<VisibilityRule> ruleList = w.getVisibility();
|
||||
if (ruleList == null) {
|
||||
return true;
|
||||
}
|
||||
if (ruleList.isEmpty()) {
|
||||
if (ruleList == null || ruleList.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
logger.debug("Checking visiblity for widget '{}'.", w.getLabel());
|
||||
|
||||
for (VisibilityRule rule : w.getVisibility()) {
|
||||
String itemName = rule.getItem();
|
||||
if (itemName == null) {
|
||||
continue;
|
||||
}
|
||||
if (rule.getState() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try and find the item to test.
|
||||
// If it's not found, return visible
|
||||
Item item;
|
||||
try {
|
||||
item = itemRegistry.getItem(itemName);
|
||||
} catch (ItemNotFoundException e) {
|
||||
logger.warn("Cannot retrieve visibility item {} for widget {}", rule.getItem(),
|
||||
w.eClass().getInstanceTypeName());
|
||||
|
||||
// Default to visible!
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the item state
|
||||
State state = item.getState();
|
||||
|
||||
// Handle the sign
|
||||
String value;
|
||||
if (rule.getSign() != null) {
|
||||
value = rule.getSign() + rule.getState();
|
||||
} else {
|
||||
value = rule.getState();
|
||||
}
|
||||
|
||||
if (matchStateToValue(state, value, rule.getCondition())) {
|
||||
// We have the name for this value!
|
||||
for (VisibilityRule rule : ruleList) {
|
||||
if (allConditionsOk(rule.getConditions(), w)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Widget {} is not visible.", w.getLabel());
|
||||
|
||||
// The state wasn't in the list, so we don't display it
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean allConditionsOk(@Nullable List<org.openhab.core.model.sitemap.sitemap.Condition> conditions,
|
||||
Widget w) {
|
||||
boolean allConditionsOk = true;
|
||||
if (conditions != null) {
|
||||
State defaultState = getState(w);
|
||||
|
||||
// Go through all AND conditions
|
||||
for (org.openhab.core.model.sitemap.sitemap.Condition condition : conditions) {
|
||||
// Use a local state variable in case it gets overridden below
|
||||
State state = defaultState;
|
||||
|
||||
// If there's an item defined here, get its state
|
||||
String itemName = condition.getItem();
|
||||
if (itemName != null) {
|
||||
// Try and find the item to test.
|
||||
Item item;
|
||||
try {
|
||||
item = itemRegistry.getItem(itemName);
|
||||
|
||||
// Get the item state
|
||||
state = item.getState();
|
||||
} catch (ItemNotFoundException e) {
|
||||
logger.warn("Cannot retrieve item {} for widget {}", itemName,
|
||||
w.eClass().getInstanceTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the sign
|
||||
String value;
|
||||
if (condition.getSign() != null) {
|
||||
value = condition.getSign() + condition.getState();
|
||||
} else {
|
||||
value = condition.getState();
|
||||
}
|
||||
|
||||
if (state == null || !matchStateToValue(state, value, condition.getCondition())) {
|
||||
allConditionsOk = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return allConditionsOk;
|
||||
}
|
||||
|
||||
enum Condition {
|
||||
EQUAL("=="),
|
||||
GTE(">="),
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.openhab.core.library.types.QuantityType;
|
|||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.model.sitemap.sitemap.ColorArray;
|
||||
import org.openhab.core.model.sitemap.sitemap.Colorpicker;
|
||||
import org.openhab.core.model.sitemap.sitemap.Condition;
|
||||
import org.openhab.core.model.sitemap.sitemap.Group;
|
||||
import org.openhab.core.model.sitemap.sitemap.Image;
|
||||
import org.openhab.core.model.sitemap.sitemap.Mapping;
|
||||
|
@ -70,6 +71,7 @@ import org.openhab.core.model.sitemap.sitemap.SitemapFactory;
|
|||
import org.openhab.core.model.sitemap.sitemap.Slider;
|
||||
import org.openhab.core.model.sitemap.sitemap.Switch;
|
||||
import org.openhab.core.model.sitemap.sitemap.Text;
|
||||
import org.openhab.core.model.sitemap.sitemap.VisibilityRule;
|
||||
import org.openhab.core.model.sitemap.sitemap.Widget;
|
||||
import org.openhab.core.types.CommandDescriptionBuilder;
|
||||
import org.openhab.core.types.CommandOption;
|
||||
|
@ -83,6 +85,7 @@ import org.openhab.core.ui.items.ItemUIProvider;
|
|||
|
||||
/**
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
* @author Laurent Garnier - Tests updated to consider multiple AND conditions + tests added for getVisiblity
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
|
@ -736,18 +739,27 @@ public class ItemUIRegistryImplTest {
|
|||
|
||||
when(widgetMock.getLabel()).thenReturn(testLabel);
|
||||
|
||||
ColorArray colorArray = mock(ColorArray.class);
|
||||
when(colorArray.getState()).thenReturn("21");
|
||||
when(colorArray.getCondition()).thenReturn("<");
|
||||
when(colorArray.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> colorArrays = new BasicEList<>();
|
||||
colorArrays.add(colorArray);
|
||||
when(widgetMock.getLabelColor()).thenReturn(colorArrays);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("21");
|
||||
when(conditon.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
ColorArray rule = mock(ColorArray.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
when(rule.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
when(widgetMock.getLabelColor()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(10f / 3f));
|
||||
|
||||
String color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("yellow", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(21f));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertNull(color);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -756,18 +768,27 @@ public class ItemUIRegistryImplTest {
|
|||
|
||||
when(widgetMock.getLabel()).thenReturn(testLabel);
|
||||
|
||||
ColorArray colorArray = mock(ColorArray.class);
|
||||
when(colorArray.getState()).thenReturn("20");
|
||||
when(colorArray.getCondition()).thenReturn("==");
|
||||
when(colorArray.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> colorArrays = new BasicEList<>();
|
||||
colorArrays.add(colorArray);
|
||||
when(widgetMock.getLabelColor()).thenReturn(colorArrays);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("20");
|
||||
when(conditon.getCondition()).thenReturn("==");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
ColorArray rule = mock(ColorArray.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
when(rule.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
when(widgetMock.getLabelColor()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new QuantityType<>("20 °C"));
|
||||
|
||||
String color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("yellow", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new QuantityType<>("20.1 °C"));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertNull(color);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -925,44 +946,108 @@ public class ItemUIRegistryImplTest {
|
|||
|
||||
when(widgetMock.getLabel()).thenReturn(testLabel);
|
||||
|
||||
ColorArray colorArray = mock(ColorArray.class);
|
||||
when(colorArray.getState()).thenReturn("21");
|
||||
when(colorArray.getCondition()).thenReturn("<");
|
||||
when(colorArray.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> colorArrays = new BasicEList<>();
|
||||
colorArrays.add(colorArray);
|
||||
ColorArray colorArray2 = mock(ColorArray.class);
|
||||
when(colorArray2.getState()).thenReturn(null);
|
||||
when(colorArray2.getCondition()).thenReturn(null);
|
||||
when(colorArray2.getArg()).thenReturn("blue");
|
||||
colorArrays.add(colorArray2);
|
||||
when(widgetMock.getLabelColor()).thenReturn(colorArrays);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("18");
|
||||
when(conditon.getCondition()).thenReturn(">=");
|
||||
Condition conditon2 = mock(Condition.class);
|
||||
when(conditon2.getState()).thenReturn("21");
|
||||
when(conditon2.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
conditions.add(conditon2);
|
||||
ColorArray rule = mock(ColorArray.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
when(rule.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
Condition conditon3 = mock(Condition.class);
|
||||
when(conditon3.getState()).thenReturn("21");
|
||||
when(conditon3.getCondition()).thenReturn(">=");
|
||||
Condition conditon4 = mock(Condition.class);
|
||||
when(conditon4.getState()).thenReturn("24");
|
||||
when(conditon4.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions2 = new BasicEList<>();
|
||||
conditions2.add(conditon3);
|
||||
conditions2.add(conditon4);
|
||||
ColorArray rule2 = mock(ColorArray.class);
|
||||
when(rule2.getConditions()).thenReturn(conditions2);
|
||||
when(rule2.getArg()).thenReturn("red");
|
||||
rules.add(rule2);
|
||||
BasicEList<Condition> conditions5 = new BasicEList<>();
|
||||
ColorArray rule3 = mock(ColorArray.class);
|
||||
when(rule3.getConditions()).thenReturn(conditions5);
|
||||
when(rule3.getArg()).thenReturn("blue");
|
||||
rules.add(rule3);
|
||||
when(widgetMock.getLabelColor()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(21.0));
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(20.9));
|
||||
|
||||
String color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("yellow", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(23.5));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("red", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
conditions5 = null;
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getLabelColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getValueColor() {
|
||||
ColorArray colorArray = mock(ColorArray.class);
|
||||
when(colorArray.getState()).thenReturn("21");
|
||||
when(colorArray.getCondition()).thenReturn("<");
|
||||
when(colorArray.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> colorArrays = new BasicEList<>();
|
||||
colorArrays.add(colorArray);
|
||||
ColorArray colorArray2 = mock(ColorArray.class);
|
||||
when(colorArray2.getState()).thenReturn("24");
|
||||
when(colorArray2.getCondition()).thenReturn("<");
|
||||
when(colorArray2.getArg()).thenReturn("red");
|
||||
colorArrays.add(colorArray2);
|
||||
ColorArray colorArray3 = mock(ColorArray.class);
|
||||
when(colorArray3.getState()).thenReturn(null);
|
||||
when(colorArray3.getCondition()).thenReturn(null);
|
||||
when(colorArray3.getArg()).thenReturn("blue");
|
||||
colorArrays.add(colorArray3);
|
||||
when(widgetMock.getValueColor()).thenReturn(colorArrays);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("18");
|
||||
when(conditon.getCondition()).thenReturn(">=");
|
||||
Condition conditon2 = mock(Condition.class);
|
||||
when(conditon2.getState()).thenReturn("21");
|
||||
when(conditon2.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
conditions.add(conditon2);
|
||||
ColorArray rule = mock(ColorArray.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
when(rule.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
Condition conditon3 = mock(Condition.class);
|
||||
when(conditon3.getState()).thenReturn("21");
|
||||
when(conditon3.getCondition()).thenReturn(">=");
|
||||
Condition conditon4 = mock(Condition.class);
|
||||
when(conditon4.getState()).thenReturn("24");
|
||||
when(conditon4.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions2 = new BasicEList<>();
|
||||
conditions2.add(conditon3);
|
||||
conditions2.add(conditon4);
|
||||
ColorArray rule2 = mock(ColorArray.class);
|
||||
when(rule2.getConditions()).thenReturn(conditions2);
|
||||
when(rule2.getArg()).thenReturn("red");
|
||||
rules.add(rule2);
|
||||
BasicEList<Condition> conditions5 = new BasicEList<>();
|
||||
ColorArray rule3 = mock(ColorArray.class);
|
||||
when(rule3.getConditions()).thenReturn(conditions5);
|
||||
when(rule3.getArg()).thenReturn("blue");
|
||||
rules.add(rule3);
|
||||
when(widgetMock.getValueColor()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(20.9));
|
||||
|
||||
|
@ -974,7 +1059,24 @@ public class ItemUIRegistryImplTest {
|
|||
color = uiRegistry.getValueColor(widgetMock);
|
||||
assertEquals("red", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(30.0));
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getValueColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getValueColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
conditions5 = null;
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getValueColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getValueColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
@ -982,23 +1084,39 @@ public class ItemUIRegistryImplTest {
|
|||
|
||||
@Test
|
||||
public void getIconColor() {
|
||||
ColorArray colorArray = mock(ColorArray.class);
|
||||
when(colorArray.getState()).thenReturn("21");
|
||||
when(colorArray.getCondition()).thenReturn("<");
|
||||
when(colorArray.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> colorArrays = new BasicEList<>();
|
||||
colorArrays.add(colorArray);
|
||||
ColorArray colorArray2 = mock(ColorArray.class);
|
||||
when(colorArray2.getState()).thenReturn("24");
|
||||
when(colorArray2.getCondition()).thenReturn("<");
|
||||
when(colorArray2.getArg()).thenReturn("red");
|
||||
colorArrays.add(colorArray2);
|
||||
ColorArray colorArray3 = mock(ColorArray.class);
|
||||
when(colorArray3.getState()).thenReturn(null);
|
||||
when(colorArray3.getCondition()).thenReturn(null);
|
||||
when(colorArray3.getArg()).thenReturn("blue");
|
||||
colorArrays.add(colorArray3);
|
||||
when(widgetMock.getIconColor()).thenReturn(colorArrays);
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("18");
|
||||
when(conditon.getCondition()).thenReturn(">=");
|
||||
Condition conditon2 = mock(Condition.class);
|
||||
when(conditon2.getState()).thenReturn("21");
|
||||
when(conditon2.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
conditions.add(conditon2);
|
||||
ColorArray rule = mock(ColorArray.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
when(rule.getArg()).thenReturn("yellow");
|
||||
BasicEList<ColorArray> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
Condition conditon3 = mock(Condition.class);
|
||||
when(conditon3.getState()).thenReturn("21");
|
||||
when(conditon3.getCondition()).thenReturn(">=");
|
||||
Condition conditon4 = mock(Condition.class);
|
||||
when(conditon4.getState()).thenReturn("24");
|
||||
when(conditon4.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions2 = new BasicEList<>();
|
||||
conditions2.add(conditon3);
|
||||
conditions2.add(conditon4);
|
||||
ColorArray rule2 = mock(ColorArray.class);
|
||||
when(rule2.getConditions()).thenReturn(conditions2);
|
||||
when(rule2.getArg()).thenReturn("red");
|
||||
rules.add(rule2);
|
||||
BasicEList<Condition> conditions5 = new BasicEList<>();
|
||||
ColorArray rule3 = mock(ColorArray.class);
|
||||
when(rule3.getConditions()).thenReturn(conditions5);
|
||||
when(rule3.getArg()).thenReturn("blue");
|
||||
rules.add(rule3);
|
||||
when(widgetMock.getIconColor()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(20.9));
|
||||
|
||||
|
@ -1010,9 +1128,60 @@ public class ItemUIRegistryImplTest {
|
|||
color = uiRegistry.getIconColor(widgetMock);
|
||||
assertEquals("red", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(30.0));
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getIconColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getIconColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
conditions5 = null;
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
color = uiRegistry.getIconColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(17.5));
|
||||
|
||||
color = uiRegistry.getIconColor(widgetMock);
|
||||
assertEquals("blue", color);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVisibility() {
|
||||
Condition conditon = mock(Condition.class);
|
||||
when(conditon.getState()).thenReturn("21");
|
||||
when(conditon.getCondition()).thenReturn(">=");
|
||||
Condition conditon2 = mock(Condition.class);
|
||||
when(conditon2.getState()).thenReturn("24");
|
||||
when(conditon2.getCondition()).thenReturn("<");
|
||||
BasicEList<Condition> conditions = new BasicEList<>();
|
||||
conditions.add(conditon);
|
||||
conditions.add(conditon2);
|
||||
VisibilityRule rule = mock(VisibilityRule.class);
|
||||
when(rule.getConditions()).thenReturn(conditions);
|
||||
BasicEList<VisibilityRule> rules = new BasicEList<>();
|
||||
rules.add(rule);
|
||||
when(widgetMock.getVisibility()).thenReturn(rules);
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(20.9));
|
||||
|
||||
assertFalse(uiRegistry.getVisiblity(widgetMock));
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(21.0));
|
||||
|
||||
assertTrue(uiRegistry.getVisiblity(widgetMock));
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(23.5));
|
||||
|
||||
assertTrue(uiRegistry.getVisiblity(widgetMock));
|
||||
|
||||
when(itemMock.getState()).thenReturn(new DecimalType(24.0));
|
||||
|
||||
assertFalse(uiRegistry.getVisiblity(widgetMock));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue