Search in sources :

Example 16 with HSBType

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);
    }
}
Also used : FatekWriteMixDataCmd(org.simplify4u.jfatek.FatekWriteMixDataCmd) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) OnOffType(org.openhab.core.library.types.OnOffType) Color(java.awt.Color) FatekException(org.simplify4u.jfatek.FatekException) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) HSBType(org.openhab.core.library.types.HSBType)

Example 17 with HSBType

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);
}
Also used : HSBType(org.openhab.core.library.types.HSBType)

Example 18 with HSBType

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);
    }
}
Also used : DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 19 with HSBType

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.");
    }
}
Also used : DecimalType(org.openhab.core.library.types.DecimalType) HSBType(org.openhab.core.library.types.HSBType)

Example 20 with HSBType

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;
}
Also used : Color(java.awt.Color) HSBType(org.openhab.core.library.types.HSBType)

Aggregations

HSBType (org.openhab.core.library.types.HSBType)30 DecimalType (org.openhab.core.library.types.DecimalType)20 PercentType (org.openhab.core.library.types.PercentType)19 Color (java.awt.Color)8 StringType (org.openhab.core.library.types.StringType)8 DateTimeType (org.openhab.core.library.types.DateTimeType)7 Calendar (java.util.Calendar)6 ColorItem (org.openhab.core.library.items.ColorItem)6 ContactItem (org.openhab.core.library.items.ContactItem)5 DateTimeItem (org.openhab.core.library.items.DateTimeItem)5 DimmerItem (org.openhab.core.library.items.DimmerItem)5 NumberItem (org.openhab.core.library.items.NumberItem)5 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 SwitchItem (org.openhab.core.library.items.SwitchItem)5 OnOffType (org.openhab.core.library.types.OnOffType)5 Test (org.junit.Test)4 State (org.openhab.core.types.State)4 DmxService (org.openhab.binding.dmx.DmxService)3 Item (org.openhab.core.items.Item)3 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)3