Skip to content

Commit

Permalink
[mqtt] set the proper unit in the state description
Browse files Browse the repository at this point in the history
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Oct 25, 2022
1 parent cf47dc0 commit 747ae9c
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public StateDescriptionFragmentBuilder createStateDescription(boolean readOnly)
if (min != null) {
builder = builder.withMinimum(min);
}
return builder.withStep(step).withPattern("%s %unit%");
if (!unit.equals(Units.ONE)) {
builder.withPattern("%s " + unit);
} else {
builder.withPattern("%s %unit%");
}
return builder.withStep(step);
}
}

0 comments on commit 747ae9c

Please sign in to comment.