Skip to content

Commit

Permalink
Avoid warning log introduced by PR #3644
Browse files Browse the repository at this point in the history
Fix openhab/openhab-webui#1951

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo committed Jul 5, 2023
1 parent 4be9578 commit ff2c494
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1373,26 +1373,29 @@ public void removeRegistryHook(RegistryHook<Item> hook) {

@Override
public @Nullable String getUnitForWidget(Widget w) {
try {
Item item = getItem(w.getItem());
String itemName = w.getItem();
if (itemName != null) {
try {
Item item = getItem(itemName);

// we require the item to define a dimension, otherwise no unit will be reported to the UIs.
if (item instanceof NumberItem numberItem && numberItem.getDimension() != null) {
String pattern = getFormatPattern(w);
if (pattern == null || pattern.isBlank()) {
// if no Label was assigned to the Widget we fallback to the items unit
return numberItem.getUnitSymbol();
}
// we require the item to define a dimension, otherwise no unit will be reported to the UIs.
if (item instanceof NumberItem numberItem && numberItem.getDimension() != null) {
String pattern = getFormatPattern(w);
if (pattern == null || pattern.isBlank()) {
// if no Label was assigned to the Widget we fallback to the items unit
return numberItem.getUnitSymbol();
}

String unit = getUnitFromPattern(pattern);
if (!UnitUtils.UNIT_PLACEHOLDER.equals(unit)) {
return unit;
}
String unit = getUnitFromPattern(pattern);
if (!UnitUtils.UNIT_PLACEHOLDER.equals(unit)) {
return unit;
}

return numberItem.getUnitSymbol();
return numberItem.getUnitSymbol();
}
} catch (ItemNotFoundException e) {
logger.warn("Failed to retrieve item during widget rendering, item does not exist: {}", e.getMessage());
}
} catch (ItemNotFoundException e) {
logger.warn("Failed to retrieve item during widget rendering, item does not exist: {}", e.getMessage());
}

return "";
Expand Down

0 comments on commit ff2c494

Please sign in to comment.