| color | Color | This channel supports full color control with hue, saturation and brightness values. | 0200, 0210, group |
| brightness | Dimmer | This channel supports adjusting the brightness value. Note that this is not available, if the color channel is supported. | 0100, 0110, 0220, group |
| color_temperature | Dimmer | This channel supports adjusting the color temperature from cold (0%) to warm (100%). | 0210, 0220, group |
-| color_temperature_abs | Number | This channel supports adjusting the color temperature in Kelvin. **Advanced** | 0210, 0220, group |
+| color_temperature_abs | Number:Temperature | This channel supports adjusting the color temperature in Kelvin. **Advanced** | 0210, 0220, group |
| alert | String | This channel supports displaying alerts by flashing the bulb either once or multiple times. Valid values are: NONE, SELECT and LSELECT. | 0000, 0100, 0200, 0210, 0220, group |
| effect | Switch | This channel supports color looping. | 0200, 0210, 0220 |
| dimmer_switch | Number | This channel shows which button was last pressed on the dimmer switch. | 0820 |
import org.openhab.core.library.types.IncreaseDecreaseType;
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.types.StringType;
+import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
}
break;
case CHANNEL_COLORTEMPERATURE_ABS:
- if (command instanceof DecimalType) {
- newState = LightStateConverter.toColorTemperatureLightState((DecimalType) command,
+ if (command instanceof QuantityType) {
+ QuantityType<?> convertedCommand = ((QuantityType<?>) command).toInvertibleUnit(Units.KELVIN);
+ if (convertedCommand != null) {
+ newState = LightStateConverter.toColorTemperatureLightState(convertedCommand.intValue(),
+ colorTemperatureCapabilties);
+ newState.setTransitionTime(fadeTime);
+ } else {
+ logger.warn("Unable to convert unit from '{}' to '{}'. Skipping command.",
+ ((QuantityType<?>) command).getUnit(), Units.KELVIN);
+ }
+ } else if (command instanceof DecimalType) {
+ newState = LightStateConverter.toColorTemperatureLightState(((DecimalType) command).intValue(),
colorTemperatureCapabilties);
newState.setTransitionTime(fadeTime);
}
}
break;
default:
+ logger.debug("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel);
break;
}
if (newState != null) {
cacheNewState(newState);
bridgeHandler.updateGroupState(group, newState, fadeTime);
} else {
- logger.debug("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel);
+ logger.debug("Unable to handle command '{}' for channel '{}'. Skipping command.", command, channel);
}
}
import org.openhab.core.library.types.IncreaseDecreaseType;
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.types.StringType;
+import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
}
break;
case CHANNEL_COLORTEMPERATURE_ABS:
- if (command instanceof DecimalType) {
- newState = LightStateConverter.toColorTemperatureLightState((DecimalType) command,
+ if (command instanceof QuantityType) {
+ QuantityType<?> convertedCommand = ((QuantityType<?>) command).toInvertibleUnit(Units.KELVIN);
+ if (convertedCommand != null) {
+ newState = LightStateConverter.toColorTemperatureLightState(convertedCommand.intValue(),
+ colorTemperatureCapabilties);
+ newState.setTransitionTime(fadeTime);
+ } else {
+ logger.warn("Unable to convert unit from '{}' to '{}'. Skipping command.",
+ ((QuantityType<?>) command).getUnit(), Units.KELVIN);
+ }
+ } else if (command instanceof DecimalType) {
+ newState = LightStateConverter.toColorTemperatureLightState(((DecimalType) command).intValue(),
colorTemperatureCapabilties);
newState.setTransitionTime(fadeTime);
}
newState = LightStateConverter.toOnOffEffectState((OnOffType) command);
}
break;
+ default:
+ logger.debug("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel);
+ break;
}
if (newState != null) {
// Cache values which we have sent
}
bridgeHandler.updateLightState(this, light, newState, fadeTime);
} else {
- logger.warn("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel);
+ logger.debug("Unable to handle command '{}' for channel '{}'. Skipping command.", command, channel);
}
}
*/
package org.openhab.binding.hue.internal.handler;
+import javax.measure.quantity.Temperature;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hue.internal.dto.ColorTemperature;
import org.openhab.core.library.types.IncreaseDecreaseType;
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.types.StringType;
+import org.openhab.core.library.unit.Units;
/**
* The {@link LightStateConverter} is responsible for mapping to/from jue types.
}
/**
- * Transforms the given {@link DecimalType} into a light state containing
- * the color temperature in Kelvin.
+ * Transforms the given color temperature in Kelvin into a Hue Light {@link State}.
*
- * @param decimalType color temperature in Kelvin
+ * @param kelvinValue color temperature in Kelvin
+ * @param capabilities color temperature capabilities (e.g. min and max values)
* @return light state containing the color temperature
*/
- public static StateUpdate toColorTemperatureLightState(DecimalType decimalType, ColorTemperature capabilities) {
- return new StateUpdate().setColorTemperature(kelvinToMired(decimalType.intValue()), capabilities);
+ public static StateUpdate toColorTemperatureLightState(int kelvinValue, ColorTemperature capabilities) {
+ return new StateUpdate().setColorTemperature(kelvinToMired(kelvinValue), capabilities);
}
/**
}
/**
- * Transforms Hue Light {@link State} into {@link DecimalType} representing
+ * Transforms Hue Light {@link State} into {@link QuantityType} representing
* the color temperature in Kelvin.
*
* @param lightState light state
- * @return percent type representing the color temperature in Kelvin
+ * @return quantity type representing the color temperature in Kelvin
*/
- public static DecimalType toColorTemperature(State lightState) {
- return new DecimalType(miredToKelvin(lightState.getColorTemperature()));
+ public static QuantityType<Temperature> toColorTemperature(State lightState) {
+ return new QuantityType<>(miredToKelvin(lightState.getColorTemperature()), Units.KELVIN);
}
/**
import org.openhab.core.library.types.IncreaseDecreaseType;
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.types.StringType;
+import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
}
@Test
- public void assertCommandForColorTemperatureAbsChannel6500Kelvin() {
+ public void assertDecimalTypeCommandForColorTemperatureAbsChannel6500Kelvin() {
String expectedReply = "{\"ct\" : 153, \"transitiontime\" : 4}";
assertSendCommandForColorTempAbs(new DecimalType(6500), new HueLightState(), expectedReply);
}
@Test
- public void assertCommandForColorTemperatureAbsChannel4500Kelvin() {
+ public void assertDecimalTypeCommandForColorTemperatureAbsChannel4500Kelvin() {
String expectedReply = "{\"ct\" : 222, \"transitiontime\" : 4}";
assertSendCommandForColorTempAbs(new DecimalType(4500), new HueLightState(), expectedReply);
}
@Test
- public void assertCommandForColorTemperatureAbsChannel2000Kelvin() {
+ public void assertDecimalTypeCommandForColorTemperatureAbsChannel2000Kelvin() {
String expectedReply = "{\"ct\" : 500, \"transitiontime\" : 4}";
assertSendCommandForColorTempAbs(new DecimalType(2000), new HueLightState(), expectedReply);
}
+ @Test
+ public void assertQuantityTypeCommandForColorTemperatureAbsChannel6500Kelvin() {
+ String expectedReply = "{\"ct\" : 153, \"transitiontime\" : 4}";
+ assertSendCommandForColorTempAbs(new QuantityType<>(6500, Units.KELVIN), new HueLightState(), expectedReply);
+ }
+
+ @Test
+ public void assertQuantityTypeCommandForColorTemperatureAbsChannel4500Kelvin() {
+ String expectedReply = "{\"ct\" : 222, \"transitiontime\" : 4}";
+ assertSendCommandForColorTempAbs(new QuantityType<>(4500, Units.KELVIN), new HueLightState(), expectedReply);
+ }
+
+ @Test
+ public void assertQuantityTypeCommandForColorTemperatureAbsChannel2000Kelvin() {
+ String expectedReply = "{\"ct\" : 500, \"transitiontime\" : 4}";
+ assertSendCommandForColorTempAbs(new QuantityType<>(2000, Units.KELVIN), new HueLightState(), expectedReply);
+ }
+
+ @Test
+ public void assertQuantityTypeCommandForColorTemperatureAbsChannel500Mired() {
+ String expectedReply = "{\"ct\" : 500, \"transitiontime\" : 4}";
+ assertSendCommandForColorTempAbs(new QuantityType<>(500, Units.MIRED), new HueLightState(), expectedReply);
+ }
+
@Test
public void assertPercentageValueOfColorTemperatureWhenCt153() {
int expectedReply = 0;
}
@Test
- public void asserCommandForColorChannelIncrease() {
+ public void assertCommandForColorChannelIncrease() {
HueLightState currentState = new HueLightState().bri(1).on(false);
String expectedReply = "{\"bri\" : 30, \"on\" : true, \"transitiontime\" : 4}";
assertSendCommandForColor(IncreaseDecreaseType.INCREASE, currentState, expectedReply);
}
@Test
- public void asserCommandForColorChannelDecrease() {
+ public void assertCommandForColorChannelDecrease() {
HueLightState currentState = new HueLightState().bri(200);
String expectedReply = "{\"bri\" : 170, \"transitiontime\" : 4}";
assertSendCommandForColor(IncreaseDecreaseType.DECREASE, currentState, expectedReply);