diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/ExtendedColorLight.xml b/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/ExtendedColorLight.xml index 8e2da5b0dce..d4d140cfb38 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/ExtendedColorLight.xml +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/ExtendedColorLight.xml @@ -17,6 +17,7 @@ + uniqueId diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/channels.xml b/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/channels.xml index 10e167cc073..2a4945a3b51 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/channels.xml +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/channels.xml @@ -73,4 +73,17 @@ The effect channel allows putting the bulb in a color looping mode. ColorLight + + + + String + + The color mode channel denotes if the bulb is in a Color or Color Temperature mode. + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.hue/META-INF/MANIFEST.MF index 40d43bfb962..11d1cb14f31 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/META-INF/MANIFEST.MF +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/META-INF/MANIFEST.MF @@ -26,6 +26,8 @@ Import-Package: org.eclipse.smarthome.core.library.types, org.eclipse.smarthome.core.thing, org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.type, org.eclipse.smarthome.core.types, org.eclipse.smarthome.io.net.http, org.jupnp.model.meta, diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/HueBindingConstants.java b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/HueBindingConstants.java index 3de85d02042..5bd5f7353e5 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/HueBindingConstants.java +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/HueBindingConstants.java @@ -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"; diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/HueLightHandler.java b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/HueLightHandler.java index ed1d21554c3..e2a22c16076 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/HueLightHandler.java +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/HueLightHandler.java @@ -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; @@ -36,6 +37,7 @@ import org.eclipse.smarthome.core.library.types.PercentType; import org.eclipse.smarthome.core.library.types.StringType; import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.Channel; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingStatus; @@ -43,6 +45,9 @@ import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder; +import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder; +import org.eclipse.smarthome.core.thing.type.ChannelTypeUID; import org.eclipse.smarthome.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,6 +130,11 @@ private void initializeThing(@Nullable ThingStatus bridgeStatus) { if (getHueClient() != null) { if (bridgeStatus == ThingStatus.ONLINE) { initializeProperties(); + + if (colorModeChannelRequired()) { + addColorModeChannel(); + } + updateStatus(ThingStatus.ONLINE); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); @@ -422,6 +432,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 @@ -512,4 +530,32 @@ private int getAlertDuration(Command command) { return delay; } + + /** + * Performs a check if the color_mode channel needs to + * be added to the remote thing + * @return true if the thing type is 0210 and + * the color_mode channel is missing + */ + private boolean colorModeChannelRequired() { + ChannelUID colorModeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_COLORMODE); + return (getThing().getThingTypeUID().equals(THING_TYPE_EXTENDED_COLOR_LIGHT)) + && (getThing().getChannel(colorModeChannelUID.getAsString()) == null); + } + + /** + * Creates the color_mode channel for + * an already paired remote thing + */ + private void addColorModeChannel() { + ChannelUID colorModeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_COLORMODE); + if (getThing().getChannel(colorModeChannelUID.getAsString()) == null) { + + Channel colorModeChannel = ChannelBuilder.create(colorModeChannelUID, "String") + .withType(new ChannelTypeUID(BINDING_ID, CHANNEL_COLORMODE)).build(); + + ThingBuilder thingBuilder = editThing().withChannel(colorModeChannel); + updateThing(thingBuilder.build()); + } + } } diff --git a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/LightStateConverter.java b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/LightStateConverter.java index 2e4c4f51fa9..e9ca3dc7b6a 100644 --- a/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/LightStateConverter.java +++ b/extensions/binding/org.eclipse.smarthome.binding.hue/src/main/java/org/eclipse/smarthome/binding/hue/handler/LightStateConverter.java @@ -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; @@ -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. @@ -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: + *
    + *
  • XY (CIE color space coordinates) and HS (Hue & saturation) color modes are mapped to {@link #COLORMODE_COLOR} + *
  • CT (color temperature) color mode is mapped to {@link #COLORMODE_COLOR_TEMPERATURE} + *
      + * + * @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) {