Search in sources :

Example 16 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType 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 17 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class LifxLightHandler method getPowerOnTemperature.

private PercentType getPowerOnTemperature() {
    ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_TEMPERATURE);
    Channel channel = getThing().getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnTemperature = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_TEMPERATURE);
    if (powerOnTemperature != null) {
        return new PercentType(powerOnTemperature.toString());
    }
    return null;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Example 18 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class LifxLightHandler method handleIncreaseDecreaseCommand.

private void handleIncreaseDecreaseCommand(IncreaseDecreaseType increaseDecrease, int zoneIndex) {
    HSBK baseColor = getLightStateForCommand().getNullSafeColor(zoneIndex);
    PercentType newBrightness = increaseDecreasePercentType(increaseDecrease, baseColor.getHSB().getBrightness());
    handlePercentCommand(newBrightness, zoneIndex);
}
Also used : HSBK(org.eclipse.smarthome.binding.lifx.internal.fields.HSBK) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Example 19 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class LifxLightHandler method getPowerOnBrightness.

private PercentType getPowerOnBrightness() {
    Channel channel = null;
    if (product.isColor()) {
        ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
        channel = getThing().getChannel(channelUID.getId());
    } else {
        ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_BRIGHTNESS);
        channel = getThing().getChannel(channelUID.getId());
    }
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnBrightness = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_BRIGHTNESS);
    return powerOnBrightness == null ? null : new PercentType(powerOnBrightness.toString());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Example 20 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class HSBK method getHSB.

public HSBType getHSB() {
    DecimalType hue = hueToDecimalType(this.hue);
    PercentType saturation = saturationToPercentType(this.saturation);
    PercentType brightness = brightnessToPercentType(this.brightness);
    return new HSBType(hue, saturation, brightness);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Aggregations

PercentType (org.eclipse.smarthome.core.library.types.PercentType)63 Test (org.junit.Test)25 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)17 State (org.eclipse.smarthome.core.types.State)17 HSBType (org.eclipse.smarthome.core.library.types.HSBType)16 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)13 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)9 StringType (org.eclipse.smarthome.core.library.types.StringType)9 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 BigDecimal (java.math.BigDecimal)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 LinkedList (java.util.LinkedList)2