mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Signed-off-by: Christian Bandowski <christian@myvm.de>
This commit is contained in:
+5
@@ -1264,6 +1264,11 @@ public class ItemUIRegistryImpl implements ItemUIRegistry {
|
||||
|
||||
// we require the item to define a dimension, otherwise no unit will be reported to the UIs.
|
||||
if (item instanceof NumberItem && ((NumberItem) item).getDimension() != null) {
|
||||
if (w.getLabel() == null) {
|
||||
// if no Label was assigned to the Widget we fallback to the items unit
|
||||
return ((NumberItem) item).getUnitSymbol();
|
||||
}
|
||||
|
||||
String unit = getUnitFromLabel(w.getLabel());
|
||||
if (!UnitUtils.UNIT_PLACEHOLDER.equals(unit)) {
|
||||
return unit;
|
||||
|
||||
+41
@@ -24,6 +24,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.measure.quantity.Temperature;
|
||||
|
||||
import org.eclipse.emf.common.util.BasicEList;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -875,4 +877,43 @@ public class ItemUIRegistryImplTest {
|
||||
defaultWidget = uiRegistry.getDefaultWidget(StringItem.class, ITEM_NAME);
|
||||
assertThat(defaultWidget, is(instanceOf(Text.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnitForWidgetForNonNumberItem() throws Exception {
|
||||
String unit = uiRegistry.getUnitForWidget(widget);
|
||||
|
||||
assertThat(unit, is(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnitForWidgetWithWidgetLabel() throws Exception {
|
||||
// a NumberItem having a Dimension must be returned
|
||||
NumberItem item = mock(NumberItem.class);
|
||||
when(registry.getItem(ITEM_NAME)).thenReturn(item);
|
||||
|
||||
doReturn(Temperature.class).when(item).getDimension();
|
||||
|
||||
// we set the Label on the widget itself
|
||||
when(widget.getLabel()).thenReturn("Label [%.1f °C]");
|
||||
|
||||
String unit = uiRegistry.getUnitForWidget(widget);
|
||||
|
||||
assertThat(unit, is(equalTo("°C")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnitForWidgetWithItemLabelAndWithoutWidgetLabel() throws Exception {
|
||||
// a NumberItem having a Dimension must be returned
|
||||
NumberItem item = mock(NumberItem.class);
|
||||
when(registry.getItem(ITEM_NAME)).thenReturn(item);
|
||||
|
||||
doReturn(Temperature.class).when(item).getDimension();
|
||||
|
||||
// we set the UnitSymbol on the item, this must be used as a fallback if no Widget label was used
|
||||
when(item.getUnitSymbol()).thenReturn("°C");
|
||||
|
||||
String unit = uiRegistry.getUnitForWidget(widget);
|
||||
|
||||
assertThat(unit, is(equalTo("°C")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user