Search in sources :

Example 1 with GetWifiInfoRequest

use of org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest 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

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 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 RefreshType (org.eclipse.smarthome.core.types.RefreshType)1