Search in sources :

Example 1 with RefreshType

use of org.eclipse.smarthome.core.types.RefreshType 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 2 with RefreshType

use of org.eclipse.smarthome.core.types.RefreshType 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 3 with RefreshType

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

Example 4 with RefreshType

use of org.eclipse.smarthome.core.types.RefreshType in project smarthome by eclipse.

the class ChaserThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    switch(channelUID.getId()) {
        case CHANNEL_SWITCH:
            if (command instanceof OnOffType) {
                if (((OnOffType) command).equals(OnOffType.ON)) {
                    Integer channelCounter = 0;
                    for (DmxChannel channel : channels) {
                        if (resumeAfter) {
                            channel.suspendAction();
                        } else {
                            channel.clearAction();
                        }
                        for (ValueSet value : values) {
                            channel.addChannelAction(new FadeAction(value.getFadeTime(), value.getValue(channelCounter), value.getHoldTime()));
                        }
                        if (resumeAfter) {
                            channel.addChannelAction(new ResumeAction());
                        }
                        channel.addListener(channelUID, this, ListenerType.ACTION);
                        channelCounter++;
                    }
                } else {
                    for (DmxChannel channel : channels) {
                        if (resumeAfter && channel.isSuspended()) {
                            channel.setChannelAction(new ResumeAction());
                        } else {
                            channel.clearAction();
                        }
                    }
                }
            } else if (command instanceof RefreshType) {
                updateState(channelUID, isRunning);
            } else {
                logger.debug("command {} not supported in channel {}:switch", command.getClass(), this.thing.getUID());
            }
            break;
        case CHANNEL_CONTROL:
            if (command instanceof StringType) {
                Vector<ValueSet> oldValues = new Vector<ValueSet>(values);
                if (parseChaserConfig(((StringType) command).toString())) {
                    logger.debug("updated chase config in {}", this.thing.getUID());
                } else {
                    // restore old chase config
                    values = oldValues;
                    logger.debug("could not update chase config in {}, malformed", this.thing.getUID());
                }
            } else {
                logger.debug("command {} not supported in channel {}:control", command.getClass(), this.thing.getUID());
            }
            break;
        default:
            logger.debug("Channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
    }
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) ResumeAction(org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Vector(java.util.Vector)

Example 5 with RefreshType

use of org.eclipse.smarthome.core.types.RefreshType in project smarthome by eclipse.

the class ColorThingHandler 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_R:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_r", this.thing.getUID());
                currentValues.set(0, channels.get(0).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(0)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_r", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_G:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_g", this.thing.getUID());
                currentValues.set(1, channels.get(1).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(1)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_g", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_B:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_b", this.thing.getUID());
                currentValues.set(2, channels.get(2).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(2)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_b", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_COLOR:
            {
                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 HSBType) {
                    logger.trace("adding color fade to channels in thing {}", this.thing.getUID());
                    targetValueSet.addValue(((HSBType) command).getRed());
                    targetValueSet.addValue(((HSBType) command).getGreen());
                    targetValueSet.addValue(((HSBType) command).getBlue());
                } else if ((command instanceof PercentType) || (command instanceof DecimalType)) {
                    logger.trace("adding brightness fade to channels in thing {}", this.thing.getUID());
                    PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
                    HSBType targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), brightness);
                    targetValueSet.addValue(targetColor.getRed());
                    targetValueSet.addValue(targetColor.getGreen());
                    targetValueSet.addValue(targetColor.getBlue());
                } 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());
                        HSBType targetColor;
                        if (((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.HUNDRED);
                        } else {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.ZERO);
                        }
                        targetValueSet.addValue(targetColor.getRed());
                        targetValueSet.addValue(targetColor.getGreen());
                        targetValueSet.addValue(targetColor.getBlue());
                        targetValueSet.setFadeTime(dimTime);
                        isDimming = true;
                    }
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:color", this.thing.getUID());
                    currentValues.set(0, channels.get(0).getValue());
                    currentValues.set(1, channels.get(1).getValue());
                    currentValues.set(2, channels.get(2).getValue());
                    updateCurrentColor();
                    updateState(channelUID, currentColor);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:color", 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()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Aggregations

OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)8 RefreshType (org.eclipse.smarthome.core.types.RefreshType)8 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)6 PercentType (org.eclipse.smarthome.core.library.types.PercentType)6 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)4 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)4 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)3 StringType (org.eclipse.smarthome.core.library.types.StringType)3 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)2 DmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel)2 HSBType (org.eclipse.smarthome.core.library.types.HSBType)2 Vector (java.util.Vector)1 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)1 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)1 ResumeAction (org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction)1 GetLightInfraredRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest)1 GetLightPowerRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest)1 GetRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest)1 GetWifiInfoRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest)1 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)1