[tapocontrol] support QuantityType commands (#17944)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2024-12-21 11:22:56 +00:00 committed by Laurent Garnier
parent 79348a30a0
commit b9add88ed9
2 changed files with 26 additions and 12 deletions

View File

@ -25,6 +25,7 @@ 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.unit.Units;
import org.openhab.core.thing.ChannelGroupUID;
import org.openhab.core.thing.ChannelUID;
@ -147,8 +148,14 @@ public class TapoBulbHandler extends TapoBaseDeviceHandler {
}
private void handleColorTempCommand(Command command) {
if (command instanceof DecimalType decimalCommand) {
setColorTemp(decimalCommand.intValue());
QuantityType<?> kelvinQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
kelvinQuantity = genericQuantity.toInvertibleUnit(Units.KELVIN);
} else if (command instanceof DecimalType decimal) {
kelvinQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN);
}
if (kelvinQuantity != null) {
setColorTemp(kelvinQuantity.intValue());
}
}

View File

@ -23,6 +23,7 @@ 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.unit.Units;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
@ -128,8 +129,14 @@ public class TapoLightStripHandler extends TapoBaseDeviceHandler {
}
private void handleColorTempCommand(Command command) {
if (command instanceof DecimalType decimalCommand) {
setColorTemp(decimalCommand.intValue());
QuantityType<?> kelvinQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
kelvinQuantity = genericQuantity.toInvertibleUnit(Units.KELVIN);
} else if (command instanceof DecimalType decimal) {
kelvinQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN);
}
if (kelvinQuantity != null) {
setColorTemp(kelvinQuantity.intValue());
}
}