diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/State.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/State.java index f32e313a10df5..5faf630504ca5 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/State.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/State.java @@ -165,6 +165,10 @@ public int getColorTemperature() { return ct; } + public void setColorTemperature(int ct) { + this.ct = ct; + } + /** * Returns the last alert mode set. * Future firmware updates may change this to actually report the current alert mode. diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java index 2199032db70fb..d2379ac64f52d 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java @@ -297,6 +297,7 @@ protected void doConnectedRun() throws IOException, ApiException { groupState.setColormode(colorRef.getColorMode()); groupState.setHue(colorRef.getHue()); groupState.setSaturation(colorRef.getSaturation()); + groupState.setColorTemperature(colorRef.getColorTemperature()); groupState.setXY(colorRef.getXY()); } logger.trace("Group {} ({}): on {} bri {} hue {} sat {} temp {} mode {} XY {}", fullGroup.getName(), diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueGroupHandler.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueGroupHandler.java index f926e18076464..392adedb19111 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueGroupHandler.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueGroupHandler.java @@ -33,9 +33,11 @@ import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.UnDefType; import org.openhab.binding.hue.internal.FullGroup; import org.openhab.binding.hue.internal.HueBridge; import org.openhab.binding.hue.internal.State; +import org.openhab.binding.hue.internal.State.ColorMode; import org.openhab.binding.hue.internal.StateUpdate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +56,7 @@ public class HueGroupHandler extends BaseThingHandler implements GroupStatusList private @NonNullByDefault({}) String groupId; + private @Nullable Integer lastSentColorTemp; private @Nullable Integer lastSentBrightness; private long defaultFadeTime = 400; @@ -182,6 +185,21 @@ public void handleCommand(String channel, Command command, long fadeTime) { } } break; + case CHANNEL_COLORTEMPERATURE: + if (command instanceof PercentType) { + groupState = LightStateConverter.toColorTemperatureLightState((PercentType) command); + if (groupState != null) { + groupState.setTransitionTime(fadeTime); + } + } else if (command instanceof OnOffType) { + groupState = LightStateConverter.toOnOffLightState((OnOffType) command); + } else if (command instanceof IncreaseDecreaseType) { + groupState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, group); + if (groupState != null) { + groupState.setTransitionTime(fadeTime); + } + } + break; case CHANNEL_BRIGHTNESS: if (command instanceof PercentType) { groupState = LightStateConverter.toBrightnessLightState((PercentType) command); @@ -196,11 +214,23 @@ public void handleCommand(String channel, Command command, long fadeTime) { groupState.setTransitionTime(fadeTime); } } + if (groupState != null && lastSentColorTemp != null) { + // make sure that the light also has the latest color temp + // this might not have been yet set in the light, if it was off + groupState.setColorTemperature(lastSentColorTemp); + groupState.setTransitionTime(fadeTime); + } break; case CHANNEL_SWITCH: if (command instanceof OnOffType) { groupState = LightStateConverter.toOnOffLightState((OnOffType) command); } + if (groupState != null && lastSentColorTemp != null) { + // make sure that the light also has the latest color temp + // this might not have been yet set in the light, if it was off + groupState.setColorTemperature(lastSentColorTemp); + groupState.setTransitionTime(fadeTime); + } break; default: break; @@ -211,12 +241,34 @@ public void handleCommand(String channel, Command command, long fadeTime) { if (tmpBrightness != null) { lastSentBrightness = tmpBrightness; } + Integer tmpColorTemp = groupState.getColorTemperature(); + if (tmpColorTemp != null) { + lastSentColorTemp = tmpColorTemp; + } hueBridge.updateGroupState(group, groupState); } else { logger.warn("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel); } } + private @Nullable StateUpdate convertColorTempChangeToStateUpdate(IncreaseDecreaseType command, FullGroup group) { + StateUpdate stateUpdate = null; + Integer currentColorTemp = getCurrentColorTemp(group.getState()); + if (currentColorTemp != null) { + int newColorTemp = LightStateConverter.toAdjustedColorTemp(command, currentColorTemp); + stateUpdate = new StateUpdate().setColorTemperature(newColorTemp); + } + return stateUpdate; + } + + private @Nullable Integer getCurrentColorTemp(@Nullable State groupState) { + Integer colorTemp = lastSentColorTemp; + if (colorTemp == null && groupState != null) { + colorTemp = groupState.getColorTemperature(); + } + return colorTemp; + } + private @Nullable StateUpdate convertBrightnessChangeToStateUpdate(IncreaseDecreaseType command, FullGroup group) { StateUpdate stateUpdate = null; Integer currentBrightness = getCurrentBrightness(group.getState()); @@ -272,6 +324,7 @@ public void onGroupStateChanged(@Nullable HueBridge bridge, FullGroup group) { return; } + lastSentColorTemp = null; lastSentBrightness = null; updateStatus(ThingStatus.ONLINE); @@ -288,6 +341,14 @@ public void onGroupStateChanged(@Nullable HueBridge bridge, FullGroup group) { } updateState(CHANNEL_COLOR, hsbType); + ColorMode colorMode = state.getColorMode(); + if (ColorMode.CT.equals(colorMode)) { + PercentType colorTempPercentType = LightStateConverter.toColorTemperaturePercentType(state); + updateState(CHANNEL_COLORTEMPERATURE, colorTempPercentType); + } else { + updateState(CHANNEL_COLORTEMPERATURE, UnDefType.NULL); + } + PercentType brightnessPercentType = LightStateConverter.toBrightnessPercentType(state); if (!state.isOn()) { brightnessPercentType = new PercentType(0); diff --git a/bundles/org.openhab.binding.hue/src/main/resources/ESH-INF/thing/Group.xml b/bundles/org.openhab.binding.hue/src/main/resources/ESH-INF/thing/Group.xml index 2d0cd0e4f6db2..0f699389a98fd 100644 --- a/bundles/org.openhab.binding.hue/src/main/resources/ESH-INF/thing/Group.xml +++ b/bundles/org.openhab.binding.hue/src/main/resources/ESH-INF/thing/Group.xml @@ -14,6 +14,7 @@ +