Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tapocontrol] Support QuantityType Color Temperature command #17944

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -147,8 +148,14 @@ private void handleColorCommand(Command command) {
}

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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -43,7 +44,7 @@ public class TapoLightStripHandler extends TapoBaseDeviceHandler {

/**
* Constructor
*
*
* @param thing Thing object representing device
*/
public TapoLightStripHandler(Thing thing) {
Expand All @@ -53,7 +54,7 @@ public TapoLightStripHandler(Thing thing) {
/**
* Function called by {@link org.openhab.binding.tapocontrol.internal.api.TapoDeviceConnector} if new data were
* received
*
*
* @param queryCommand command where new data belong to
*/
@Override
Expand All @@ -71,7 +72,7 @@ public void newDataResult(String queryCommand) {

/**
* handle command sent to device
*
*
* @param channelUID channelUID command is sent to
* @param command command to be sent
*/
Expand Down Expand Up @@ -128,8 +129,14 @@ private void handleColorCommand(Command command) {
}

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());
}
}

Expand Down Expand Up @@ -164,7 +171,7 @@ private void handleLightFx(String channel, Command command) {

/**
* Switch device On or Off
*
*
* @param on if true device will switch on. Otherwise switch off
*/
protected void switchOnOff(boolean on) {
Expand All @@ -174,7 +181,7 @@ protected void switchOnOff(boolean on) {

/**
* Set Britghtness of device
*
*
* @param newBrightness percentage 0-100 of new brightness
*/
protected void setBrightness(Integer newBrightness) {
Expand All @@ -190,7 +197,7 @@ protected void setBrightness(Integer newBrightness) {

/**
* Set Color of Device
*
*
* @param command HSBType
*/
protected void setColor(HSBType command) {
Expand All @@ -203,7 +210,7 @@ protected void setColor(HSBType command) {

/**
* Set ColorTemp
*
*
* @param colorTemp (Integer) in Kelvin
*/
protected void setColorTemp(Integer colorTemp) {
Expand All @@ -214,7 +221,7 @@ protected void setColorTemp(Integer colorTemp) {

/**
* Set light effect
*
*
* @param lightEffect TapoLightEffect
*/
protected void setLightEffect(TapoLightEffect lightEffect) {
Expand Down