[sitemap] Allow default color condition for labelcolor and valuecolor (#2995)

Closes openhab/openhab-webui#1298

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2022-06-04 18:22:27 +02:00 committed by GitHub
parent 2ae3137fec
commit c61baf7600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 2 deletions

View File

@ -1104,8 +1104,10 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
State cmpState = state;
if (color.getState() == null) {
logger.error("Error parsing color");
continue;
// 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

View File

@ -918,4 +918,65 @@ public class ItemUIRegistryImplTest {
assertThat(unit, is(equalTo("°C")));
}
@Test
public void getLabelColorDefaultColor() {
String testLabel = "Label [%.3f]";
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);
when(itemMock.getState()).thenReturn(new DecimalType(21.0));
String 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);
when(itemMock.getState()).thenReturn(new DecimalType(20.9));
String color = uiRegistry.getValueColor(widgetMock);
assertEquals("yellow", color);
when(itemMock.getState()).thenReturn(new DecimalType(23.5));
color = uiRegistry.getValueColor(widgetMock);
assertEquals("red", color);
when(itemMock.getState()).thenReturn(new DecimalType(30.0));
color = uiRegistry.getValueColor(widgetMock);
assertEquals("blue", color);
}
}