Search in sources :

Example 6 with IncreaseDecreaseType

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);
    }
}
Also used : StateUpdate(org.eclipse.smarthome.binding.hue.internal.StateUpdate) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) FullLight(org.eclipse.smarthome.binding.hue.internal.FullLight) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 7 with IncreaseDecreaseType

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>" + "&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

IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 PercentType (org.eclipse.smarthome.core.library.types.PercentType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)6 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)3 HSBType (org.eclipse.smarthome.core.library.types.HSBType)3 StringType (org.eclipse.smarthome.core.library.types.StringType)2 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 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)1 DmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel)1 FullLight (org.eclipse.smarthome.binding.hue.internal.FullLight)1 StateUpdate (org.eclipse.smarthome.binding.hue.internal.StateUpdate)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