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

[BasicUI] Fix unit determination for min/max from item state description #2894

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from 1 commit
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
lolodomo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,24 @@ private BigDecimal getMaximumInKelvin(Colortemperaturepicker widget, Unit<?> wid
}

private boolean isUnitInKelvin(StateDescription stateDescription) {
// If no pattern or pattern with no unit, assume unit for min and max is Kelvin
Unit<?> unit = UnitUtils.parseUnit(stateDescription.getPattern());
return unit == null || unit == Units.KELVIN;
// Using the pattern to determine the unit of min/max is not fully reliable
// because the user can override the pattern and set a different unit than
// the one defined by binding developer at channel level.
// So we consider the values of min/max to determine the unit of the range.
// If values are lower than 1000, we assume values are in mirek.
// If values are greater than 1000, we assume values are in Kelvin.
boolean inKelvin;
BigDecimal min = stateDescription.getMinimum();
BigDecimal max = stateDescription.getMaximum();
if (min != null) {
inKelvin = min.doubleValue() >= 1000.0;
} else if (max != null) {
inKelvin = max.doubleValue() > 1000.0;
} else {
// If no pattern or pattern with no unit, assume unit is Kelvin
Unit<?> unit = UnitUtils.parseUnit(stateDescription.getPattern());
inKelvin = unit == null || unit == Units.KELVIN;
}
return inKelvin;
}
}