[deconz] support QuantityType commands (#17942)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Andrew Fiddian-Green 2024-12-21 11:12:55 +00:00 committed by Ciprian Pascu
parent 61d2239512
commit 13f7225a0b
2 changed files with 20 additions and 7 deletions

View File

@ -14,7 +14,6 @@ package org.openhab.binding.deconz.internal.handler;
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;
@ -36,7 +35,9 @@ import org.openhab.core.library.types.DecimalType;
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;
@ -139,9 +140,15 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
}
}
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;
}
}

View File

@ -245,9 +245,15 @@ public class LightThingHandler extends DeconzBaseThingHandler {
}
}
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;
}
}