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);
}
}
}
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;
}
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);
}
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());
}
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);
}
Aggregations