Skip to content

Commit

Permalink
item unit from state description
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <[email protected]>
  • Loading branch information
mherwege committed Jul 1, 2023
1 parent 9653d2d commit 0925db0
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openhab.core.model.sitemap.sitemap.Input;
import org.openhab.core.model.sitemap.sitemap.Widget;
import org.openhab.core.types.State;
import org.openhab.core.types.StateDescription;
import org.openhab.core.types.UnDefType;
import org.openhab.core.types.util.UnitUtils;
import org.openhab.core.ui.items.ItemUIRegistry;
Expand Down Expand Up @@ -256,9 +257,20 @@ private String getUnit(Widget w, NumberItem item) {
if (w.getLabel() != null) {
unit = getUnitFromLabel(item, w.getLabel());
}
// required when item is defined through UI and the label contains the value format pattern
if ((unit != null) && unit.isBlank() && (item.getLabel() != null)) {
unit = getUnitFromLabel(item, item.getLabel());
}
// required when the value pattern is in the state description (text definition or meta data)
if ((unit != null) && unit.isBlank()) {
StateDescription stateDescription = item.getStateDescription();
if (stateDescription != null) {
String pattern = stateDescription.getPattern();
if (pattern != null) {
unit = getUnitFromLabel(item, "[" + pattern + "]");
}
}
}
if (unit == null || unit.isBlank()) {
unit = item.getUnitSymbol();
}
Expand Down

0 comments on commit 0925db0

Please sign in to comment.