Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Implemented Color Mode channel for the Extended Color Light.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kostadinov <[email protected]>
  • Loading branch information
alex-kostadinov committed Jun 29, 2018
1 parent d0caf85 commit 022eecb
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.binding.hue.internal.State;
import org.eclipse.smarthome.binding.hue.internal.State.AlertMode;
import org.eclipse.smarthome.binding.hue.internal.State.ColorMode;
import org.eclipse.smarthome.binding.hue.internal.State.Effect;
import org.eclipse.smarthome.binding.hue.internal.StateUpdate;
import org.eclipse.smarthome.core.library.types.DecimalType;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class LightStateConverter {
private static final int MAX_COLOR_TEMPERATURE = 500;
private static final int COLOR_TEMPERATURE_RANGE = MAX_COLOR_TEMPERATURE - MIN_COLOR_TEMPERATURE;


/**
* {@value #ALERT_MODE_NONE}. The light is not performing an alert effect.
*/
Expand Down Expand Up @@ -164,9 +166,16 @@ public static int toAdjustedColorTemp(IncreaseDecreaseType type, int currentColo
* the color temperature.
*
* @param lightState light state
* @return percent type representing the color temperature
* @return percent type representing the color temperature or null
* if the bulb's {@link ColorMode} denotes the value is not applicable for setting color temperature
* (i.e. the bulb's color mode is not {@link ColorMode.CT}).
*/
public static PercentType toColorTemperaturePercentType(State lightState) {
public static @Nullable PercentType toColorTemperaturePercentType(State lightState) {
ColorMode colorMode = lightState.getColorMode();
if (colorMode != null && !colorMode.equals(ColorMode.CT)) {
return null;
}

int percent = (int) Math
.round(((lightState.getColorTemperature() - MIN_COLOR_TEMPERATURE) * 100.0) / COLOR_TEMPERATURE_RANGE);
return new PercentType(restrictToBounds(percent));
Expand Down

0 comments on commit 022eecb

Please sign in to comment.