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

* [various] process color temperature quantity type commands

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:32:03 +00:00 committed by Ciprian Pascu
parent ff8d95a420
commit 1c26aea3a0

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