From ff2c4942dd4ecd51d4802e794843772a89345a76 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Wed, 5 Jul 2023 19:27:00 +0200 Subject: [PATCH] Avoid warning log introduced by PR #3644 Fix openhab/openhab-webui#1951 Signed-off-by: Laurent Garnier --- .../ui/internal/items/ItemUIRegistryImpl.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java index d5a69469427..1862082e2e8 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java @@ -1373,26 +1373,29 @@ public void removeRegistryHook(RegistryHook 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 "";