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

Avoid item not found warning from UIRegistry #3686

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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 @@ -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