Skip to content

Commit

Permalink
[amazonechocontrol] Support QuantityType Color Temperature command (o…
Browse files Browse the repository at this point in the history
…penhab#17919)

* [various] process color temperature quantity type commands

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
  • Loading branch information
andrewfg authored Dec 21, 2024
1 parent 31e0bb6 commit 6acfeb6
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
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;
Expand Down Expand Up @@ -130,15 +132,21 @@ public boolean handleCommand(Connection connection, SmartHomeDevice shd, String
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 (kelvinQuantity != null) {
int kelvin = kelvinQuantity.intValue();
if (kelvin < 1000) {
kelvin = 1000;
}
if (intValue > 10000) {
intValue = 10000;
if (kelvin > 10000) {
kelvin = 10000;
}
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", intValue);
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", kelvin);
return true;
}
}
Expand Down

0 comments on commit 6acfeb6

Please sign in to comment.