Search in sources :

Example 1 with OnOffType

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;
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) State(org.eclipse.smarthome.core.types.State) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 2 with OnOffType

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>&lt;attribute&gt;&lt;name&gt;Brewed&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;" + "&lt;attribute&gt;&lt;name&gt;LastCleaned&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;" + "&lt;name&gt;ModeTime&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;Brewing&lt;/name&gt;" + "&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;TimeRemaining&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;" + "&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;WaterLevelReached&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;" + "attribute&gt;&lt;name&gt;Mode&lt;/name&gt;&lt;value&gt;4&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;CleanAdvise&lt;/name&gt;" + "&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;FilterAdvise&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;" + "&lt;attribute&gt;&lt;name&gt;Cleaning&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;</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);
        }
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State) RefreshType(org.eclipse.smarthome.core.types.RefreshType)

Example 3 with OnOffType

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;
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType)

Example 4 with OnOffType

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);
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) UpDownType(org.eclipse.smarthome.core.library.types.UpDownType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) StopMoveType(org.eclipse.smarthome.core.library.types.StopMoveType)

Example 5 with OnOffType

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);
        }
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) GetWifiInfoRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest) GetRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest) GetLightInfraredRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) GetLightPowerRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Aggregations

OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)21 PercentType (org.eclipse.smarthome.core.library.types.PercentType)10 RefreshType (org.eclipse.smarthome.core.types.RefreshType)8 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 State (org.eclipse.smarthome.core.types.State)7 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)6 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)4 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)4 StringType (org.eclipse.smarthome.core.library.types.StringType)4 HSBType (org.eclipse.smarthome.core.library.types.HSBType)3 ZonedDateTime (java.time.ZonedDateTime)2 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)2 DmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel)2 OpenClosedType (org.eclipse.smarthome.core.library.types.OpenClosedType)2 FilterCriteria (org.eclipse.smarthome.core.persistence.FilterCriteria)2 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)2 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)2 Test (org.junit.Test)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1