use of org.eclipse.smarthome.core.library.types.IncreaseDecreaseType 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.core.library.types.IncreaseDecreaseType 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