[amazonechocontrol] Support QuantityType Color Temperature command (#17919)

* [various] process color temperature quantity type commands

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2024-12-21 11:32:03 +00:00 committed by GitHub
parent 31e0bb601c
commit 6acfeb65f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,7 +26,9 @@ import org.openhab.binding.amazonechocontrol.internal.handler.SmartHomeDeviceHan
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonSmartHomeCapabilities.SmartHomeCapability;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonSmartHomeDevices.SmartHomeDevice;
import org.openhab.core.library.types.DecimalType;
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.DefaultSystemChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
@ -130,15 +132,21 @@ public class HandlerColorTemperatureController extends HandlerBase {
if (channelId.equals(COLOR_TEMPERATURE_IN_KELVIN.channelId)) {
// WRITING TO THIS CHANNEL DOES CURRENTLY NOT WORK, BUT WE LEAVE THE CODE FOR FUTURE USE!
if (containsCapabilityProperty(capabilities, COLOR_TEMPERATURE_IN_KELVIN.propertyName)) {
if (command instanceof DecimalType) {
int intValue = ((DecimalType) command).intValue();
if (intValue < 1000) {
intValue = 1000;
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 (intValue > 10000) {
intValue = 10000;
if (kelvinQuantity != null) {
int kelvin = kelvinQuantity.intValue();
if (kelvin < 1000) {
kelvin = 1000;
}
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", intValue);
if (kelvin > 10000) {
kelvin = 10000;
}
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", kelvin);
return true;
}
}