diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java index 641bab0fd40..bd49dddf081 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/helper/Setters.java @@ -22,8 +22,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; -import javax.measure.Unit; - import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.hue.internal.api.dto.clip2.Alerts; @@ -97,23 +95,13 @@ public class Setters { * @return the target resource. */ public static Resource setColorTemperatureAbsolute(Resource target, Command command, @Nullable Resource source) { - QuantityType mirek; - if (command instanceof QuantityType quantity) { - Unit unit = quantity.getUnit(); - if (Units.KELVIN.equals(unit)) { - mirek = quantity.toInvertibleUnit(Units.MIRED); - } else if (Units.MIRED.equals(unit)) { - mirek = quantity; - } else { - QuantityType kelvin = quantity.toInvertibleUnit(Units.KELVIN); - mirek = Objects.nonNull(kelvin) ? kelvin.toInvertibleUnit(Units.MIRED) : null; - } + QuantityType mirekQuantity = null; + if (command instanceof QuantityType genericQuantity) { + mirekQuantity = genericQuantity.toInvertibleUnit(Units.MIRED); } else if (command instanceof DecimalType decimal) { - mirek = QuantityType.valueOf(decimal.doubleValue(), Units.KELVIN).toInvertibleUnit(Units.MIRED); - } else { - mirek = null; + mirekQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN).toInvertibleUnit(Units.MIRED); } - if (Objects.nonNull(mirek)) { + if (Objects.nonNull(mirekQuantity)) { MirekSchema schema = target.getMirekSchema(); schema = Objects.nonNull(schema) ? schema : Objects.nonNull(source) ? source.getMirekSchema() : null; schema = Objects.nonNull(schema) ? schema : MirekSchema.DEFAULT_SCHEMA; @@ -121,7 +109,7 @@ public class Setters { colorTemperature = Objects.nonNull(colorTemperature) ? colorTemperature : new ColorTemperature(); double min = schema.getMirekMinimum(); double max = schema.getMirekMaximum(); - double val = Math.max(min, Math.min(max, mirek.doubleValue())); + double val = Math.max(min, Math.min(max, mirekQuantity.doubleValue())); target.setColorTemperature(colorTemperature.setMirek(val)); } return target;