use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.
the class FatekColorItem method command.
@Override
public void command(FatekPLC fatekPLC, Command command) throws CommandException {
try {
final HSBType val;
if (command instanceof OnOffType) {
val = valueForOnOff(fatekPLC, command);
} else if (command instanceof IncreaseDecreaseType) {
val = valueForIncreaseDecrease(fatekPLC, command);
} else if (command instanceof HSBType) {
val = (HSBType) command;
} else {
throw new UnsupportedCommandException(this, command);
}
if (val != null) {
int v1;
int v2;
int v3;
if (isColorRGB) {
Color c = val.toColor();
v1 = c.getRed();
v2 = c.getGreen();
v3 = c.getBlue();
} else {
v1 = val.getHue().intValue();
v2 = val.getSaturation().intValue();
v3 = val.getBrightness().intValue();
}
FatekWriteMixDataCmd cmd = new FatekWriteMixDataCmd(fatekPLC);
cmd.addReg(reg1, v1);
cmd.addReg(reg2, v2);
cmd.addReg(reg3, v3);
cmd.send();
}
} catch (FatekIOException | FatekException e) {
throw new CommandException(this, command, e);
}
}
use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.
the class JointSpaceBinding method setAmbilightColor.
/**
* Sets the ambilight color specified in command (which must be an HSBType
* until now) for the pixel(s) specified with @see layers.
*
* @param host
* @param command
* HSBType command to set the color
* @param layers
* pixel(s) to set the color for. null if all pixels should have
* the same value
*/
private void setAmbilightColor(String host, Command command, String[] layers) {
if (!(command instanceof HSBType)) {
logger.warn("Until now only HSBType is allowed for ambilight commands");
return;
}
logger.debug("Setting Ambilight color for host {} and layer {} to {}", host, layers, command.toString());
HSBType hsbcommand = (HSBType) command;
String url = "http://" + host + "/1/ambilight/cached";
StringBuilder content = new StringBuilder();
content.append("{");
int count = 0;
if (layers != null) {
for (int i = 0; i < layers.length; i++) {
content.append("\"" + layers[i] + "\":{");
count++;
}
}
int red = Math.round(hsbcommand.getRed().floatValue() * 2.55f);
int green = Math.round(hsbcommand.getGreen().floatValue() * 2.55f);
int blue = Math.round(hsbcommand.getBlue().floatValue() * 2.55f);
content.append("\"r\":" + red + ", \"g\":" + green + ", \"b\":" + blue);
for (int i = 0; i < count; i++) {
content.append("}");
}
content.append("}");
logger.trace("Trying to post json for ambilight: {}", content.toString());
HttpUtil.executeUrl("POST", url, IOUtils.toInputStream(content.toString()), CONTENT_TYPE_JSON, 1000);
}
use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.
the class MilightBinding method internalReceiveCommand.
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
super.internalReceiveCommand(itemName, command);
MilightBindingConfig deviceConfig = getConfigForItemName(itemName);
if (deviceConfig == null) {
return;
}
try {
int bulb = deviceConfig.getChannelNumber();
int rgbwSteps = deviceConfig.getSteps();
String bridgeId = deviceConfig.getDeviceId();
if (deviceConfig.getCommandType().equals(BindingType.brightness)) {
logger.debug("milight: item is of type brightness");
if (OnOffType.ON.equals(command)) {
sendOn(bulb, bridgeId);
} else if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
PercentType newValue = sendIncrease(bulb, rgbwSteps, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
PercentType newValue = sendDecrease(bulb, rgbwSteps, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (command instanceof PercentType) {
logger.debug("milight: command is of type PercentType");
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.brightness);
}
} else if (deviceConfig.getCommandType().equals(BindingType.nightMode)) {
logger.debug("milight: item is of type nightMode");
if (OnOffType.ON.equals(command)) {
sendNightMode(bulb, bridgeId);
}
if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
} else if (deviceConfig.getCommandType().equals(BindingType.whiteMode)) {
logger.debug("milight: item is of type whiteMode");
if (OnOffType.ON.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendWhiteMode(bulb, bridgeId);
}
if (OnOffType.OFF.equals(command)) {
sendOff(bulb, bridgeId);
}
} else if (deviceConfig.getCommandType().equals(BindingType.colorTemperature)) {
logger.debug("milight: item is of type warm/cold white");
if (OnOffType.ON.equals(command)) {
sendPercent(bulb, rgbwSteps, bridgeId, PercentType.HUNDRED, BindingType.colorTemperature);
} else if (OnOffType.OFF.equals(command)) {
sendPercent(bulb, rgbwSteps, bridgeId, PercentType.ZERO, BindingType.colorTemperature);
} else if (IncreaseDecreaseType.INCREASE.equals(command)) {
PercentType newValue = sendWarmer(bulb, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
PercentType newValue = sendCooler(bulb, bridgeId);
eventPublisher.postUpdate(itemName, newValue);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.colorTemperature);
}
} else if (deviceConfig.getCommandType().equals(BindingType.discoMode)) {
logger.debug("milight: item is of type discoMode");
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendDiscoModeUp(bulb, bridgeId);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
sendDiscoModeDown(bulb, bridgeId);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.discoMode);
}
} else if (deviceConfig.getCommandType().equals(BindingType.discoSpeed)) {
logger.debug("milight: item is of type discoSpeed");
if (IncreaseDecreaseType.INCREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendIncreaseSpeed(bulb, bridgeId);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendDecreaseSpeed(bulb, bridgeId);
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.discoSpeed);
}
} else if (deviceConfig.getCommandType().equals(BindingType.rgb)) {
logger.debug("milight: item is of type rgb");
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
DecimalType saturation = hsbCommand.getSaturation();
if (saturation.equals(0)) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
sendWhiteMode(bulb, bridgeId);
} else {
sendColor(command, bridgeId, bulb);
}
} else if (command instanceof PercentType) {
sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.brightness);
}
}
} catch (Exception e) {
logger.error("milight: Failed to send {} command ", deviceConfig.getCommandType(), e);
}
}
use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.
the class MilightBinding method sendColor.
private void sendColor(Command command, String bridgeId, int bulb) {
logger.debug("milight: sendColor");
HSBType hsbCommand = (HSBType) command;
DecimalType hue = hsbCommand.getHue();
// we have to map [0,360] to [0,0xFF], where red equals hue=0 and the milight color 0xB0 (=176)
Integer milightColorNo = (256 + 176 - (int) (hue.floatValue() / 360.0 * 255.0)) % 256;
try {
if (bulb == 5) {
String messageBytes = "20:" + Integer.toHexString(milightColorNo) + ":55";
sendMessage(messageBytes, bridgeId);
}
if (bulb > 5) {
sendOn(bulb, bridgeId);
Thread.sleep(100);
String messageBytes = "40:" + Integer.toHexString(milightColorNo) + ":55";
sendMessage(messageBytes, bridgeId);
}
} catch (InterruptedException e) {
logger.debug("Sleeping thread has been interrupted.");
}
}
use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.
the class SoulissT16 method getOHStateRGB.
/**
* Returns the values in HSB, use RGB as input
*
* @return org.openhab.core.types.State
*/
public org.openhab.core.types.State getOHStateRGB() {
Color colr = new Color(this.stateRED, this.stateGREEN, this.stateBLU);
HSBType hsb = new HSBType(colr);
return hsb;
}
Aggregations