Search in sources :

Example 6 with RefreshType

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()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) 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)

Example 7 with RefreshType

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()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) 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)

Example 8 with RefreshType

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>" + "&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;DeviceStatus&gt;&lt;DeviceID&gt;" + wemoLightID + "&lt;/DeviceID&gt;&lt;IsGroupAction&gt;NO&lt;/IsGroupAction&gt;&lt;CapabilityID&gt;" + capability + "&lt;/CapabilityID&gt;&lt;CapabilityValue&gt;" + value + "&lt;/CapabilityValue&gt;&lt;/DeviceStatus&gt;" + "</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);
        }
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType)

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