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

[hue] Improve color setting #16436

Merged
merged 10 commits into from
Apr 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ public static Resource setColorTemperaturePercent(Resource target, Command comma
* @return the target resource.
*/
public static Resource setColorXy(Resource target, Command command, @Nullable Resource source) {
if (command instanceof HSBType) {
if (command instanceof HSBType cmdHsb) {
Gamut gamut = target.getGamut();
gamut = Objects.nonNull(gamut) ? gamut : Objects.nonNull(source) ? source.getGamut() : null;
gamut = Objects.nonNull(gamut) ? gamut : ColorUtil.DEFAULT_GAMUT;
HSBType hsb = (HSBType) command;
HSBType hsb = cmdHsb.getBrightness().doubleValue() >= 0.1 ? cmdHsb
: new HSBType(cmdHsb.getHue(), cmdHsb.getBrightness(), new PercentType(BigDecimal.valueOf(0.1)));
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
ColorXy color = target.getColorXy();
target.setColorXy((Objects.nonNull(color) ? color : new ColorXy()).setXY(ColorUtil.hsbToXY(hsb, gamut)));
}
Expand Down