Skip to content

Commit

Permalink
[tapocontrol] support QuantityType commands (openhab#17944)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg authored Dec 21, 2024
1 parent 57577f4 commit 31e0bb6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
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

0 comments on commit 31e0bb6

Please sign in to comment.