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 21, 2018
1 parent 98686f2 commit 4e0c010
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<channel id="color_temperature" typeId="color_temperature" />
<channel id="alert" typeId="alert" />
<channel id="effect" typeId="effect" />
<channel id="color_mode" typeId="color_mode" />
</channels>

<representation-property>uniqueId</representation-property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,17 @@
<description>The effect channel allows putting the bulb in a color looping mode.</description>
<category>ColorLight</category>
</channel-type>

<!-- Color Mode Channel -->
<channel-type id="color_mode" advanced="true">
<item-type>String</item-type>
<label>Color Mode</label>
<description>The color mode channel denotes if the bulb is in a Color or Color Temperature mode.</description>
<state readOnly="true">
<options>
<option value="COLOR">Color Mode</option>
<option value="COLOR_TEMPERATURE">Color Temperature Mode</option>
</options>
</state>
</channel-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class HueBindingConstants {
public static final String CHANNEL_ALERT = "alert";
public static final String CHANNEL_EFFECT = "effect";
public static final String CHANNEL_SWITCH = "switch";
public static final String CHANNEL_COLORMODE = "color_mode";

// Bridge config properties
public static final String HOST = "ipAddress";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.smarthome.binding.hue.internal.FullLight;
import org.eclipse.smarthome.binding.hue.internal.HueBridge;
import org.eclipse.smarthome.binding.hue.internal.State;
import org.eclipse.smarthome.binding.hue.internal.State.ColorMode;
import org.eclipse.smarthome.binding.hue.internal.StateUpdate;
import org.eclipse.smarthome.core.library.types.HSBType;
import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType;
Expand Down Expand Up @@ -422,6 +423,14 @@ public void onLightStateChanged(@Nullable HueBridge bridge, FullLight fullLight)
updateState(CHANNEL_ALERT, stringType);
scheduleAlertStateRestore(stringType);
}

ColorMode colorMode = fullLight.getState().getColorMode();
if (colorMode != null) {
updateState(CHANNEL_COLORMODE, LightStateConverter.toColorModeStringType(colorMode));
} else {
// By default fall back to pure Hue & Saturation color mode
updateState(CHANNEL_COLORMODE, LightStateConverter.toColorModeStringType(ColorMode.HS));
}
}

@Override
Expand Down
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 @@ -47,6 +48,9 @@ public class LightStateConverter {
private static final int MIN_COLOR_TEMPERATURE = 153;
private static final int MAX_COLOR_TEMPERATURE = 500;
private static final int COLOR_TEMPERATURE_RANGE = MAX_COLOR_TEMPERATURE - MIN_COLOR_TEMPERATURE;

public static final String COLORMODE_COLOR = "COLOR";
public static final String COLORMODE_COLOR_TEMPERATURE = "COLOR_TEMPERATURE";

/**
* {@value #ALERT_MODE_NONE}. The light is not performing an alert effect.
Expand Down Expand Up @@ -265,6 +269,29 @@ public static StateUpdate toOnOffEffectState(OnOffType onOffType) {

return stateUpdate;
}

/**
* Transforms a given {@link ColorMode} to its corresponding {@link StringType} as follows:
* Supported values are:
* <ul>
* <li>XY (CIE color space coordinates) and HS (Hue & saturation) color modes are mapped to {@link #COLORMODE_COLOR}
* <li>CT (color temperature) color mode is mapped to {@link #COLORMODE_COLOR_TEMPERATURE}
* <ul>
*
* @param {@link ColorMode} colorMode
* @return A {@link StringType} representing the given ColorMode
*/
public static StringType toColorModeStringType(@Nullable ColorMode colorMode) {
switch (colorMode) {
case XY:
case HS:
return new StringType(COLORMODE_COLOR);
case CT:
return new StringType(COLORMODE_COLOR_TEMPERATURE);
default:
return new StringType(COLORMODE_COLOR);
}
}

private static int restrictToBounds(int percentValue) {
if (percentValue < 0) {
Expand Down

0 comments on commit 4e0c010

Please sign in to comment.