use of org.eclipse.smarthome.core.types.RefreshType in project smarthome by eclipse.
the class DimmerThingHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("received command {} in channel {}", command, channelUID);
ValueSet targetValueSet = new ValueSet(fadeTime, -1);
switch(channelUID.getId()) {
case CHANNEL_BRIGHTNESS:
{
if (command instanceof PercentType || command instanceof DecimalType) {
PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
logger.trace("adding fade to channels in thing {}", this.thing.getUID());
targetValueSet.addValue(brightness);
} else if (command instanceof OnOffType) {
logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
} else if (command instanceof IncreaseDecreaseType) {
if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
logger.trace("stopping fade in thing {}", this.thing.getUID());
channels.forEach(DmxChannel::clearAction);
isDimming = false;
return;
} else {
logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue;
targetValueSet.setFadeTime(dimTime);
isDimming = true;
}
} else if (command instanceof RefreshType) {
logger.trace("sending update on refresh to channel {}:brightness", this.thing.getUID());
currentBrightness = Util.toPercentValue(channels.get(0).getValue());
updateState(channelUID, currentBrightness);
return;
} else {
logger.debug("command {} not supported in channel {}:brightness", command.getClass(), this.thing.getUID());
return;
}
break;
}
default:
logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
return;
}
final ValueSet valueSet = targetValueSet;
IntStream.range(0, channels.size()).forEach(i -> {
channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
});
}
use of org.eclipse.smarthome.core.types.RefreshType in project smarthome by eclipse.
the class TunableWhiteThingHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("received command {} in channel {}", command, channelUID);
ValueSet targetValueSet = new ValueSet(fadeTime, -1);
switch(channelUID.getId()) {
case CHANNEL_BRIGHTNESS:
{
if (command instanceof PercentType || command instanceof DecimalType) {
PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
logger.trace("adding fade to channels in thing {}", this.thing.getUID());
targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(brightness) * (100 - currentColorTemperature.intValue()) / 100));
targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(brightness) * currentColorTemperature.intValue() / 100));
} else if (command instanceof OnOffType) {
logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
} else if (command instanceof IncreaseDecreaseType) {
if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
logger.trace("stopping fade in thing {}", this.thing.getUID());
channels.forEach(DmxChannel::clearAction);
isDimming = false;
return;
} else {
logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue;
targetValueSet.setFadeTime(dimTime);
isDimming = true;
}
} else if (command instanceof RefreshType) {
logger.trace("sending update on refresh to channel {}:brightness", this.thing.getUID());
currentValues.set(0, channels.get(0).getValue());
currentValues.set(1, channels.get(1).getValue());
updateCurrentBrightnessAndTemperature();
updateState(channelUID, currentBrightness);
return;
} else {
logger.debug("command {} not supported in channel {}:brightness", command.getClass(), this.thing.getUID());
return;
}
break;
}
case CHANNEL_BRIGHTNESS_CW:
if (command instanceof RefreshType) {
logger.trace("sending update on refresh to channel {}:brightness_cw", this.thing.getUID());
currentValues.set(0, channels.get(0).getValue());
updateState(channelUID, Util.toPercentValue(currentValues.get(0)));
return;
} else {
logger.debug("command {} not supported in channel {}:brightness_cw", command.getClass(), this.thing.getUID());
return;
}
case CHANNEL_BRIGHTNESS_WW:
if (command instanceof RefreshType) {
logger.trace("sending update on refresh to channel {}:brightness_ww", this.thing.getUID());
currentValues.set(1, channels.get(1).getValue());
updateState(channelUID, Util.toPercentValue(currentValues.get(1)));
return;
} else {
logger.debug("command {} not supported in channel {}:brightness_ww", command.getClass(), this.thing.getUID());
return;
}
case CHANNEL_COLOR_TEMPERATURE:
{
if (command instanceof PercentType) {
PercentType colorTemperature = (PercentType) command;
targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(currentBrightness) * (100 - colorTemperature.intValue()) / 100));
targetValueSet.addValue(Util.toDmxValue(Util.toDmxValue(currentBrightness) * colorTemperature.intValue() / 100));
} else if (command instanceof RefreshType) {
logger.trace("sending update on refresh to channel {}:color_temperature", this.thing.getUID());
currentValues.set(0, channels.get(0).getValue());
currentValues.set(1, channels.get(1).getValue());
updateCurrentBrightnessAndTemperature();
updateState(channelUID, currentColorTemperature);
return;
} else {
logger.debug("command {} not supported in channel {}:color_temperature", command.getClass(), this.thing.getUID());
return;
}
break;
}
default:
logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
return;
}
final ValueSet valueSet = targetValueSet;
IntStream.range(0, channels.size()).forEach(i -> {
channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
});
}
use of org.eclipse.smarthome.core.types.RefreshType in project smarthome by eclipse.
the class WemoLightHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
try {
getDeviceState();
} catch (Exception e) {
logger.debug("Exception during poll : {}", e);
}
} else {
Configuration configuration = getConfig();
configuration.get(DEVICE_ID);
WemoBridgeHandler wemoBridge = getWemoBridgeHandler();
if (wemoBridge == null) {
logger.debug("wemoBridgeHandler not found, cannot handle command");
return;
}
String devUDN = "uuid:" + wemoBridge.getThing().getConfiguration().get(UDN).toString();
logger.trace("WeMo Bridge to send command to : {}", devUDN);
String value = null;
String capability = null;
switch(channelUID.getId()) {
case CHANNEL_BRIGHTNESS:
capability = "10008";
if (command instanceof PercentType) {
int newBrightness = ((PercentType) command).intValue();
logger.trace("wemoLight received Value {}", newBrightness);
int value1 = Math.round(newBrightness * 255 / 100);
value = value1 + ":0";
currentBrightness = newBrightness;
} else if (command instanceof OnOffType) {
switch(command.toString()) {
case "ON":
value = "255:0";
break;
case "OFF":
value = "0:0";
break;
}
} else if (command instanceof IncreaseDecreaseType) {
int newBrightness;
switch(command.toString()) {
case "INCREASE":
currentBrightness = currentBrightness + DIM_STEPSIZE;
newBrightness = Math.round(currentBrightness * 255 / 100);
if (newBrightness > 255) {
newBrightness = 255;
}
value = newBrightness + ":0";
break;
case "DECREASE":
currentBrightness = currentBrightness - DIM_STEPSIZE;
newBrightness = Math.round(currentBrightness * 255 / 100);
if (newBrightness < 0) {
newBrightness = 0;
}
value = newBrightness + ":0";
break;
}
}
break;
case CHANNEL_STATE:
capability = "10006";
switch(command.toString()) {
case "ON":
value = "1";
break;
case "OFF":
value = "0";
break;
}
break;
}
try {
String soapHeader = "\"urn:Belkin:service:bridge:1#SetDeviceStatus\"";
String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:SetDeviceStatus xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DeviceStatusList>" + "<?xml version="1.0" encoding="UTF-8"?><DeviceStatus><DeviceID>" + wemoLightID + "</DeviceID><IsGroupAction>NO</IsGroupAction><CapabilityID>" + capability + "</CapabilityID><CapabilityValue>" + value + "</CapabilityValue></DeviceStatus>" + "</DeviceStatusList>" + "</u:SetDeviceStatus>" + "</s:Body>" + "</s:Envelope>";
String wemoURL = getWemoURL();
if (wemoURL != null && capability != null && value != null) {
String wemoCallResponse = WemoHttpCall.executeCall(wemoURL, soapHeader, content);
if (wemoCallResponse != null) {
if (capability != null && capability.equals("10008") && value != null) {
OnOffType binaryState = null;
binaryState = value.equals("0") ? OnOffType.OFF : OnOffType.ON;
if (binaryState != null) {
updateState(CHANNEL_STATE, binaryState);
}
}
}
}
} catch (Exception e) {
throw new RuntimeException("Could not send command to WeMo Bridge", e);
}
}
}
Aggregations