use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class ColorpickerRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Colorpicker cp = (Colorpicker) w;
String snippetName = "colorpicker";
String snippet = getSnippet(snippetName);
// set the default send-update frequency to 200ms
String frequency = cp.getFrequency() == 0 ? "200" : Integer.toString(cp.getFrequency());
// get RGB hex value
State state = itemUIRegistry.getState(cp);
String hexValue = "#ffffff";
if (state instanceof HSBType) {
HSBType hsbState = (HSBType) state;
hexValue = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
}
String label = getLabel(cp);
String purelabel = itemUIRegistry.getLabel(w);
purelabel = purelabel.replaceAll("\\\"", "\\\\'");
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(cp));
snippet = StringUtils.replace(snippet, "%category%", getCategory(cp));
snippet = StringUtils.replace(snippet, "%item%", w.getItem());
snippet = StringUtils.replace(snippet, "%label%", label);
snippet = StringUtils.replace(snippet, "%format%", getFormat());
snippet = StringUtils.replace(snippet, "%purelabel%", purelabel);
snippet = StringUtils.replace(snippet, "%state%", hexValue);
snippet = StringUtils.replace(snippet, "%frequency%", frequency);
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
String style = "";
String color = itemUIRegistry.getLabelColor(w);
if (color != null) {
style = "color:" + color;
}
snippet = StringUtils.replace(snippet, "%labelstyle%", style);
style = "";
color = itemUIRegistry.getValueColor(w);
if (color != null) {
style = "color:" + color;
}
snippet = StringUtils.replace(snippet, "%valuestyle%", style);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class ColorItem method setState.
@Override
public void setState(State state) {
if (isAcceptedState(acceptedDataTypes, state)) {
State currentState = this.state;
if (currentState instanceof HSBType) {
DecimalType hue = ((HSBType) currentState).getHue();
PercentType saturation = ((HSBType) currentState).getSaturation();
// we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed
if (state == OnOffType.OFF) {
applyState(new HSBType(hue, saturation, PercentType.ZERO));
} else if (state == OnOffType.ON) {
applyState(new HSBType(hue, saturation, PercentType.HUNDRED));
} else if (state instanceof PercentType && !(state instanceof HSBType)) {
applyState(new HSBType(hue, saturation, (PercentType) state));
} else if (state instanceof DecimalType && !(state instanceof HSBType)) {
applyState(new HSBType(hue, saturation, new PercentType(((DecimalType) state).toBigDecimal().multiply(BigDecimal.valueOf(100)))));
} else {
applyState(state);
}
} else {
// try conversion
State convertedState = state.as(HSBType.class);
if (convertedState != null) {
applyState(convertedState);
} else {
applyState(state);
}
}
} else {
logSetTypeError(state);
}
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class HueLightHandler method onLightStateChanged.
@Override
public void onLightStateChanged(@Nullable HueBridge bridge, FullLight fullLight) {
logger.trace("onLightStateChanged() was called");
if (!fullLight.getId().equals(lightId)) {
logger.trace("Received state change for another handler's light ({}). Will be ignored.", fullLight.getId());
return;
}
initializeProperties();
lastSentColorTemp = null;
lastSentBrightness = null;
// update status (ONLINE, OFFLINE)
if (fullLight.getState().isReachable()) {
updateStatus(ThingStatus.ONLINE);
} else {
// we assume OFFLINE without any error (NONE), as this is an
// expected state (when bulb powered off)
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/offline.light-not-reachable");
}
HSBType hsbType = LightStateConverter.toHSBType(fullLight.getState());
if (!fullLight.getState().isOn()) {
hsbType = new HSBType(hsbType.getHue(), hsbType.getSaturation(), new PercentType(0));
}
updateState(CHANNEL_COLOR, hsbType);
PercentType percentType = LightStateConverter.toColorTemperaturePercentType(fullLight.getState());
updateState(CHANNEL_COLORTEMPERATURE, percentType);
percentType = LightStateConverter.toBrightnessPercentType(fullLight.getState());
if (!fullLight.getState().isOn()) {
percentType = new PercentType(0);
}
updateState(CHANNEL_BRIGHTNESS, percentType);
if (fullLight.getState().isOn()) {
updateState(CHANNEL_SWITCH, OnOffType.ON);
} else {
updateState(CHANNEL_SWITCH, OnOffType.OFF);
}
StringType stringType = LightStateConverter.toAlertStringType(fullLight.getState());
if (!stringType.toString().equals("NULL")) {
updateState(CHANNEL_ALERT, stringType);
scheduleAlertStateRestore(stringType);
}
}
use of org.eclipse.smarthome.core.library.types.HSBType 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);
}
}
Aggregations