import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.hue.internal.handler.HueLightHandler;
+import org.openhab.binding.hue.internal.handler.HueLightActionsHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.library.types.DecimalType;
import org.slf4j.LoggerFactory;
/**
- * The {@link LightActions} defines the thing actions for the hue binding.
+ * The {@link LightActions} defines {@link ThingActions} for the hue lights.
*
* @author Jochen Leopold - Initial contribution
- * @author Laurent Garnier - new method invokeMethodOf + interface ILightActions
*/
@ThingActionsScope(name = "hue")
@NonNullByDefault
public class LightActions implements ThingActions {
private final Logger logger = LoggerFactory.getLogger(LightActions.class);
- private @Nullable HueLightHandler handler;
+ private @Nullable HueLightActionsHandler handler;
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
- this.handler = (HueLightHandler) handler;
+ this.handler = (HueLightActionsHandler) handler;
}
@Override
@ActionInput(name = "channel", label = "@text/actionInputChannelLabel", description = "@text/actionInputChannelDesc") @Nullable String channel,
@ActionInput(name = "command", label = "@text/actionInputCommandLabel", description = "@text/actionInputCommandDesc") @Nullable Command command,
@ActionInput(name = "fadeTime", label = "@text/actionInputFadeTimeLabel", description = "@text/actionInputFadeTimeDesc") @Nullable DecimalType fadeTime) {
- HueLightHandler lightHandler = handler;
- if (lightHandler == null) {
+ HueLightActionsHandler lightActionsHandler = handler;
+ if (lightActionsHandler == null) {
logger.warn("Hue Action service ThingHandler is null!");
return;
}
logger.debug("skipping Hue fadingLightCommand to channel '{}' due to null value.", channel);
return;
}
-
if (command == null) {
logger.debug("skipping Hue fadingLightCommand to command '{}' due to null value.", command);
return;
return;
}
- lightHandler.handleCommand(channel, command, fadeTime.longValue());
- logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime);
+ lightActionsHandler.handleCommand(channel, command, fadeTime.longValue());
+ logger.debug("send fadingLightCommand to channel '{}' with fadeTime of {}ms.", channel, fadeTime);
}
public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command,
import static org.openhab.core.thing.Thing.*;
import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.openhab.binding.hue.internal.FullLight;
import org.openhab.binding.hue.internal.State;
import org.openhab.binding.hue.internal.StateUpdate;
-import org.openhab.binding.hue.internal.action.LightActions;
import org.openhab.binding.hue.internal.dto.Capabilities;
import org.openhab.binding.hue.internal.dto.ColorTemperature;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.ThingHandler;
-import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.types.Command;
import org.openhab.core.types.StateDescriptionFragment;
import org.openhab.core.types.StateDescriptionFragmentBuilder;
* @author Jochen Leopold - Added support for custom fade times
*/
@NonNullByDefault
-public class HueLightHandler extends BaseThingHandler implements LightStatusListener {
+public class HueLightHandler extends BaseThingHandler implements HueLightActionsHandler, LightStatusListener {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_COLOR_LIGHT,
THING_TYPE_COLOR_TEMPERATURE_LIGHT, THING_TYPE_DIMMABLE_LIGHT, THING_TYPE_EXTENDED_COLOR_LIGHT,
handleCommand(channelUID.getId(), command, defaultFadeTime);
}
+ @Override
public void handleCommand(String channel, Command command, long fadeTime) {
HueClient bridgeHandler = getHueClient();
if (bridgeHandler == null) {
}
Integer lastColorTemp;
- StateUpdate lightState = null;
+ StateUpdate newState = null;
switch (channel) {
case CHANNEL_COLORTEMPERATURE:
if (command instanceof PercentType) {
- lightState = LightStateConverter.toColorTemperatureLightStateFromPercentType((PercentType) command,
+ newState = LightStateConverter.toColorTemperatureLightStateFromPercentType((PercentType) command,
colorTemperatureCapabilties);
- lightState.setTransitionTime(fadeTime);
+ newState.setTransitionTime(fadeTime);
} else if (command instanceof OnOffType) {
- lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
+ newState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
- lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
+ newState = addOsramSpecificCommands(newState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
- lightState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, light);
- if (lightState != null) {
- lightState.setTransitionTime(fadeTime);
+ newState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, light);
+ if (newState != null) {
+ newState.setTransitionTime(fadeTime);
}
}
break;
case CHANNEL_COLORTEMPERATURE_ABS:
if (command instanceof DecimalType) {
- lightState = LightStateConverter.toColorTemperatureLightState((DecimalType) command,
+ newState = LightStateConverter.toColorTemperatureLightState((DecimalType) command,
colorTemperatureCapabilties);
- lightState.setTransitionTime(fadeTime);
+ newState.setTransitionTime(fadeTime);
}
break;
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType) {
- lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
- lightState.setTransitionTime(fadeTime);
+ newState = LightStateConverter.toBrightnessLightState((PercentType) command);
+ newState.setTransitionTime(fadeTime);
} else if (command instanceof OnOffType) {
- lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
+ newState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
- lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
+ newState = addOsramSpecificCommands(newState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
- lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
- if (lightState != null) {
- lightState.setTransitionTime(fadeTime);
+ newState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
+ if (newState != null) {
+ newState.setTransitionTime(fadeTime);
}
}
lastColorTemp = lastSentColorTemp;
- if (lightState != null && lastColorTemp != null) {
+ if (newState != null && lastColorTemp != 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
- lightState.setColorTemperature(lastColorTemp, colorTemperatureCapabilties);
- lightState.setTransitionTime(fadeTime);
+ newState.setColorTemperature(lastColorTemp, colorTemperatureCapabilties);
+ newState.setTransitionTime(fadeTime);
}
break;
case CHANNEL_SWITCH:
if (command instanceof OnOffType) {
- lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
+ newState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
- lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
+ newState = addOsramSpecificCommands(newState, (OnOffType) command);
}
}
lastColorTemp = lastSentColorTemp;
- if (lightState != null && lastColorTemp != null) {
+ if (newState != null && lastColorTemp != 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
- lightState.setColorTemperature(lastColorTemp, colorTemperatureCapabilties);
- lightState.setTransitionTime(fadeTime);
+ newState.setColorTemperature(lastColorTemp, colorTemperatureCapabilties);
+ newState.setTransitionTime(fadeTime);
}
break;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
if (hsbCommand.getBrightness().intValue() == 0) {
- lightState = LightStateConverter.toOnOffLightState(OnOffType.OFF);
+ newState = LightStateConverter.toOnOffLightState(OnOffType.OFF);
} else {
- lightState = LightStateConverter.toColorLightState(hsbCommand, light.getState());
- lightState.setTransitionTime(fadeTime);
+ newState = LightStateConverter.toColorLightState(hsbCommand, light.getState());
+ newState.setTransitionTime(fadeTime);
}
} else if (command instanceof PercentType) {
- lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
- lightState.setTransitionTime(fadeTime);
+ newState = LightStateConverter.toBrightnessLightState((PercentType) command);
+ newState.setTransitionTime(fadeTime);
} else if (command instanceof OnOffType) {
- lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
+ newState = LightStateConverter.toOnOffLightState((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
- lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
- if (lightState != null) {
- lightState.setTransitionTime(fadeTime);
+ newState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
+ if (newState != null) {
+ newState.setTransitionTime(fadeTime);
}
}
break;
case CHANNEL_ALERT:
if (command instanceof StringType) {
- lightState = LightStateConverter.toAlertState((StringType) command);
- if (lightState == null) {
+ newState = LightStateConverter.toAlertState((StringType) command);
+ if (newState == null) {
// Unsupported StringType is passed. Log a warning
// message and return.
logger.warn("Unsupported String command: {}. Supported commands are: {}, {}, {} ", command,
break;
case CHANNEL_EFFECT:
if (command instanceof OnOffType) {
- lightState = LightStateConverter.toOnOffEffectState((OnOffType) command);
+ newState = LightStateConverter.toOnOffEffectState((OnOffType) command);
}
break;
}
- if (lightState != null) {
+ if (newState != null) {
// Cache values which we have sent
- Integer tmpBrightness = lightState.getBrightness();
+ Integer tmpBrightness = newState.getBrightness();
if (tmpBrightness != null) {
lastSentBrightness = tmpBrightness;
}
- Integer tmpColorTemp = lightState.getColorTemperature();
+ Integer tmpColorTemp = newState.getColorTemperature();
if (tmpColorTemp != null) {
lastSentColorTemp = tmpColorTemp;
}
- bridgeHandler.updateLightState(this, light, lightState, fadeTime);
+ bridgeHandler.updateLightState(this, light, newState, fadeTime);
} else {
logger.warn("Command sent to an unknown channel id: {}:{}", getThing().getUID(), channel);
}
return delay;
}
- @Override
- public Collection<Class<? extends ThingHandlerService>> getServices() {
- return List.of(LightActions.class);
- }
-
@Override
public String getLightId() {
return lightId;