Skip to content

Commit

Permalink
[deconz] support QuantityType commands (openhab#17942)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg authored and lolodomo committed Dec 21, 2024
1 parent a100c27 commit e84a582
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.openhab.binding.deconz.internal.BindingConstants.*;
import static org.openhab.binding.deconz.internal.Util.constrainToRange;
import static org.openhab.binding.deconz.internal.Util.kelvinToMired;

import java.util.Collection;
import java.util.Map;
Expand All @@ -36,7 +35,9 @@
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -139,9 +140,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_COLOR_TEMPERATURE -> {
if (command instanceof DecimalType decimalCommand) {
int miredValue = kelvinToMired(decimalCommand.intValue());
newGroupAction.ct = constrainToRange(miredValue, ZCL_CT_MIN, ZCL_CT_MAX);
QuantityType<?> miredQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
miredQuantity = genericQuantity.toInvertibleUnit(Units.MIRED);
} else if (command instanceof DecimalType decimal) {
miredQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN)
.toInvertibleUnit(Units.MIRED);
}
if (miredQuantity != null) {
newGroupAction.ct = constrainToRange(miredQuantity.intValue(), ZCL_CT_MIN, ZCL_CT_MAX);
newGroupAction.on = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_COLOR_TEMPERATURE -> {
if (command instanceof DecimalType) {
int miredValue = kelvinToMired(((DecimalType) command).intValue());
newLightState.ct = constrainToRange(miredValue, ctMin, ctMax);
QuantityType<?> miredQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
miredQuantity = genericQuantity.toInvertibleUnit(Units.MIRED);
} else if (command instanceof DecimalType decimal) {
miredQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN)
.toInvertibleUnit(Units.MIRED);
}
if (miredQuantity != null) {
newLightState.ct = constrainToRange(miredQuantity.intValue(), ctMin, ctMax);
newLightState.on = true;
}
}
Expand Down

0 comments on commit e84a582

Please sign in to comment.