use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class WemoLightHandler method onValueReceived.
@Override
public void onValueReceived(String variable, String value, String service) {
logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() });
String capabilityId = StringUtils.substringBetween(value, "<CapabilityId>", "</CapabilityId>");
String newValue = StringUtils.substringBetween(value, "<Value>", "</Value>");
switch(capabilityId) {
case "10006":
OnOffType binaryState = null;
binaryState = newValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
if (binaryState != null) {
updateState(CHANNEL_STATE, binaryState);
}
break;
case "10008":
String[] splitValue = newValue.split(":");
if (splitValue[0] != null) {
int newBrightnessValue = Integer.valueOf(splitValue[0]);
int newBrightness = Math.round(newBrightnessValue * 100 / 255);
State newBrightnessState = new PercentType(newBrightness);
updateState(CHANNEL_BRIGHTNESS, newBrightnessState);
currentBrightness = newBrightness;
}
break;
}
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class WemoCoffeeHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("Command '{}' received for channel '{}'", command, channelUID);
if (command instanceof RefreshType) {
try {
updateWemoState();
} catch (Exception e) {
logger.debug("Exception during poll : {}", e);
}
} else if (channelUID.getId().equals(CHANNEL_STATE)) {
if (command instanceof OnOffType) {
if (command.equals(OnOffType.ON)) {
try {
String soapHeader = "\"urn:Belkin:service:deviceevent:1#SetAttributes\"";
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:SetAttributes xmlns:u=\"urn:Belkin:service:deviceevent:1\">" + "<attributeList><attribute><name>Brewed</name><value>NULL</value></attribute>" + "<attribute><name>LastCleaned</name><value>NULL</value></attribute><attribute>" + "<name>ModeTime</name><value>NULL</value></attribute><attribute><name>Brewing</name>" + "<value>NULL</value></attribute><attribute><name>TimeRemaining</name><value>NULL</value>" + "</attribute><attribute><name>WaterLevelReached</name><value>NULL</value></attribute><" + "attribute><name>Mode</name><value>4</value></attribute><attribute><name>CleanAdvise</name>" + "<value>NULL</value></attribute><attribute><name>FilterAdvise</name><value>NULL</value></attribute>" + "<attribute><name>Cleaning</name><value>NULL</value></attribute></attributeList>" + "</u:SetAttributes>" + "</s:Body>" + "</s:Envelope>";
String wemoURL = getWemoURL("deviceevent");
if (wemoURL != null) {
String wemoCallResponse = WemoHttpCall.executeCall(wemoURL, soapHeader, content);
if (wemoCallResponse != null) {
updateState(CHANNEL_STATE, OnOffType.ON);
State newMode = new StringType("Brewing");
updateState(CHANNEL_COFFEEMODE, newMode);
}
}
} catch (Exception e) {
logger.error("Failed to send command '{}' for device '{}': {}", command, getThing().getUID(), e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
}
}
// if command.equals(OnOffType.OFF) we do nothing because WeMo Coffee Maker cannot be switched off
// remotely
updateStatus(ThingStatus.ONLINE);
}
}
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class RawButtonToggleSwitchProfile method onTriggerFromHandler.
@Override
public void onTriggerFromHandler(String event) {
if (CommonTriggerEvents.PRESSED.equals(event)) {
OnOffType newState = OnOffType.ON.equals(previousState) ? OnOffType.OFF : OnOffType.ON;
callback.sendCommand(newState);
previousState = newState;
}
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class DeviceHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
BridgeHandler dssBridgeHandler = getDssBridgeHandler();
if (dssBridgeHandler == null) {
logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
return;
}
if (device == null) {
logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
return;
}
if (command instanceof RefreshType) {
try {
SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
} catch (IllegalArgumentException e) {
dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
}
} else if (!device.isShade()) {
if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
if (command instanceof PercentType) {
device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setIsOn(true);
} else {
device.setIsOn(false);
}
} else if (command instanceof IncreaseDecreaseType) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
device.increase();
} else {
device.decrease();
}
} else if (command instanceof StringType) {
device.setOutputValue(Short.parseShort(((StringType) command).toString()));
}
} else {
logger.debug("Command sent to an unknown channel id: {}", channelUID);
}
} else {
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
if (command instanceof PercentType) {
device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setAnglePosition(device.getMaxSlatAngle());
} else {
device.setAnglePosition(device.getMinSlatAngle());
}
} else if (command instanceof IncreaseDecreaseType) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
device.increaseSlatAngle();
} else {
device.decreaseSlatAngle();
}
}
} else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
if (command instanceof PercentType) {
int percent = ((PercentType) command).intValue();
if (!device.getHWinfo().equals("GR-KL200")) {
percent = 100 - percent;
}
device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
this.lastComand = command;
} else if (command instanceof StopMoveType) {
if (StopMoveType.MOVE.equals(command)) {
handleCommand(channelUID, this.lastComand);
} else {
dssBridgeHandler.stopOutputValue(device);
}
} else if (command instanceof UpDownType) {
if (UpDownType.UP.equals(command)) {
device.setIsOpen(true);
this.lastComand = command;
} else {
device.setIsOpen(false);
this.lastComand = command;
}
}
} else {
logger.debug("Command sent to an unknown channel id: {}", channelUID);
}
}
}
use of org.eclipse.smarthome.core.library.types.OnOffType in project smarthome by eclipse.
the class LifxLightHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
switch(channelUID.getId()) {
case CHANNEL_COLOR:
case CHANNEL_BRIGHTNESS:
sendPacket(new GetLightPowerRequest());
sendPacket(new GetRequest());
break;
case CHANNEL_TEMPERATURE:
sendPacket(new GetRequest());
break;
case CHANNEL_INFRARED:
sendPacket(new GetLightInfraredRequest());
break;
case CHANNEL_SIGNAL_STRENGTH:
sendPacket(new GetWifiInfoRequest());
break;
default:
break;
}
} else {
boolean supportedCommand = true;
switch(channelUID.getId()) {
case CHANNEL_COLOR:
if (command instanceof HSBType) {
handleHSBCommand((HSBType) command);
} else if (command instanceof PercentType) {
handlePercentCommand((PercentType) command);
} else if (command instanceof OnOffType) {
handleOnOffCommand((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
} else {
supportedCommand = false;
}
break;
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType) {
handlePercentCommand((PercentType) command);
} else if (command instanceof OnOffType) {
handleOnOffCommand((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
} else {
supportedCommand = false;
}
break;
case CHANNEL_TEMPERATURE:
if (command instanceof PercentType) {
handleTemperatureCommand((PercentType) command);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command);
} else {
supportedCommand = false;
}
break;
case CHANNEL_INFRARED:
if (command instanceof PercentType) {
handleInfraredCommand((PercentType) command);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseInfraredCommand((IncreaseDecreaseType) command);
} else {
supportedCommand = false;
}
break;
default:
try {
if (channelUID.getId().startsWith(CHANNEL_COLOR_ZONE)) {
int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_COLOR_ZONE, ""));
if (command instanceof HSBType) {
handleHSBCommand((HSBType) command, zoneIndex);
} else if (command instanceof PercentType) {
handlePercentCommand((PercentType) command, zoneIndex);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseCommand((IncreaseDecreaseType) command, zoneIndex);
} else {
supportedCommand = false;
}
} else if (channelUID.getId().startsWith(CHANNEL_TEMPERATURE_ZONE)) {
int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_TEMPERATURE_ZONE, ""));
if (command instanceof PercentType) {
handleTemperatureCommand((PercentType) command, zoneIndex);
} else if (command instanceof IncreaseDecreaseType) {
handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command, zoneIndex);
} else {
supportedCommand = false;
}
} else {
supportedCommand = false;
}
} catch (NumberFormatException e) {
logger.error("Failed to parse zone index for a command of a light ({}) : {}", logId, e.getMessage());
supportedCommand = false;
}
break;
}
if (supportedCommand && !(command instanceof OnOffType) && !CHANNEL_INFRARED.equals(channelUID.getId())) {
getLightStateForCommand().setPowerState(PowerState.ON);
}
}
}
Aggregations