use of org.eclipse.smarthome.binding.hue.internal.StateUpdate in project smarthome by eclipse.
the class LightStateConverter method toColorLightState.
/**
* Transforms the given {@link HSBType} into a light state.
*
* @param hsbType HSB type
* @return light state representing the {@link HSBType}.
*/
public static StateUpdate toColorLightState(HSBType hsbType) {
int hue = (int) Math.round(hsbType.getHue().doubleValue() * HUE_FACTOR);
int saturation = (int) Math.round(hsbType.getSaturation().doubleValue() * SATURATION_FACTOR);
int brightness = (int) Math.round(hsbType.getBrightness().doubleValue() * BRIGHTNESS_FACTOR);
StateUpdate stateUpdate = new StateUpdate().setHue(hue).setSat(saturation);
if (brightness > 0) {
stateUpdate.setBrightness(brightness);
}
return stateUpdate;
}
use of org.eclipse.smarthome.binding.hue.internal.StateUpdate in project smarthome by eclipse.
the class HueLightHandler method convertBrightnessChangeToStateUpdate.
@Nullable
private StateUpdate convertBrightnessChangeToStateUpdate(IncreaseDecreaseType command, FullLight light) {
StateUpdate stateUpdate = null;
Integer currentBrightness = getCurrentBrightness(light.getState());
if (currentBrightness != null) {
int newBrightness = LightStateConverter.toAdjustedBrightness(command, currentBrightness);
stateUpdate = createBrightnessStateUpdate(currentBrightness, newBrightness);
lastSentBrightness = newBrightness;
}
return stateUpdate;
}
use of org.eclipse.smarthome.binding.hue.internal.StateUpdate in project smarthome by eclipse.
the class HueLightHandler method convertColorTempChangeToStateUpdate.
@Nullable
private StateUpdate convertColorTempChangeToStateUpdate(IncreaseDecreaseType command, FullLight light) {
StateUpdate stateUpdate = null;
Integer currentColorTemp = getCurrentColorTemp(light.getState());
if (currentColorTemp != null) {
int newColorTemp = LightStateConverter.toAdjustedColorTemp(command, currentColorTemp);
stateUpdate = new StateUpdate().setColorTemperature(newColorTemp);
lastSentColorTemp = newColorTemp;
}
return stateUpdate;
}
use of org.eclipse.smarthome.binding.hue.internal.StateUpdate in project smarthome by eclipse.
the class HueLightHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
HueBridgeHandler hueBridge = getHueBridgeHandler();
if (hueBridge == null) {
logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
return;
}
FullLight light = getLight();
if (light == null) {
logger.debug("hue light not known on bridge. Cannot handle command.");
return;
}
StateUpdate lightState = null;
switch(channelUID.getId()) {
case CHANNEL_COLORTEMPERATURE:
if (command instanceof PercentType) {
lightState = LightStateConverter.toColorTemperatureLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType) {
lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_SWITCH:
logger.trace("CHANNEL_SWITCH handling command {}", command);
if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
}
break;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
if (hsbCommand.getBrightness().intValue() == 0) {
lightState = LightStateConverter.toOnOffLightState(OnOffType.OFF);
} else {
lightState = LightStateConverter.toColorLightState(hsbCommand);
}
} else if (command instanceof PercentType) {
lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_ALERT:
if (command instanceof StringType) {
lightState = LightStateConverter.toAlertState((StringType) command);
if (lightState == null) {
// Unsupported StringType is passed. Log a warning
// message and return.
logger.warn("Unsupported String command: {}. Supported commands are: {}, {}, {} ", command, LightStateConverter.ALERT_MODE_NONE, LightStateConverter.ALERT_MODE_SELECT, LightStateConverter.ALERT_MODE_LONG_SELECT);
return;
} else {
scheduleAlertStateRestore(command);
}
}
break;
case CHANNEL_EFFECT:
if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffEffectState((OnOffType) command);
}
break;
}
if (lightState != null) {
hueBridge.updateLightState(light, lightState);
} else {
logger.warn("Command sent to an unknown channel id: {}", channelUID);
}
}
use of org.eclipse.smarthome.binding.hue.internal.StateUpdate in project smarthome by eclipse.
the class LightStateConverter method toBrightnessLightState.
/**
* Transforms the given {@link PercentType} into a light state containing
* the brightness and the 'on' value represented by {@link PercentType}.
*
* @param percentType brightness represented as {@link PercentType}
* @return light state containing the brightness and the 'on' value
*/
public static StateUpdate toBrightnessLightState(PercentType percentType) {
boolean on = !percentType.equals(PercentType.ZERO);
final StateUpdate stateUpdate = new StateUpdate().setOn(on);
int brightness = (int) Math.round(percentType.floatValue() * BRIGHTNESS_FACTOR);
if (brightness > 0) {
stateUpdate.setBrightness(brightness);
}
return stateUpdate;
}
Aggregations