Search in sources :

Example 1 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class ColorColorImpl method setSensorValue.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setSensorValue(HSBValue newSensorValue) {
    HSBValue oldSensorValue = sensorValue;
    sensorValue = newSensorValue;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.COLOR_COLOR__SENSOR_VALUE, oldSensorValue, sensorValue));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue)

Example 2 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class LEDGroupImpl method setSelectedColor.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void setSelectedColor(HSBType color) {
    // get the rgb values from HSBType
    Color rgbColor = color.toColor();
    short red = (short) rgbColor.getRed();
    short green = (short) rgbColor.getGreen();
    short blue = (short) rgbColor.getBlue();
    logger.debug("rgb is: {}:{}:{}", red, green, blue);
    // construct the values for the setRGBValues call
    HashMap<Character, short[]> colorMap = new HashMap<Character, short[]>(3);
    short[] reds = { red, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red };
    short[] greens = { green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green };
    short[] blues = { blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue };
    colorMap.put('r', reds);
    colorMap.put('g', greens);
    colorMap.put('b', blues);
    try {
        if (ledList.hasLedRanges()) {
            Map<Integer, Short> ledRanges = ledList.getLedRanges();
            for (Integer led : ledRanges.keySet()) {
                logger.debug("setting color for range from led {} to range {}", led, ledRanges.get(led));
                logger.debug("color from mapping{},{},{}", colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
                tinkerforgeDevice.setRGBValues(led, ledRanges.get(led), colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
            }
        }
        if (ledList.hasLeds()) {
            for (Integer led : ledList.getLedNumbers()) {
                logger.debug("setting color for led {}", led);
                logger.debug("color from mapping{},{},{}", colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
                tinkerforgeDevice.setRGBValues(led, (short) 1, colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
            }
        }
        setColor(new HSBValue(color));
    } catch (TimeoutException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
    } catch (NotConnectedException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
    }
}
Also used : NotConnectedException(com.tinkerforge.NotConnectedException) HashMap(java.util.HashMap) Color(java.awt.Color) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue) TimeoutException(com.tinkerforge.TimeoutException)

Example 3 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class LEDGroupImpl method setColor.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setColor(HSBValue newColor) {
    HSBValue oldColor = color;
    color = newColor;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.LED_GROUP__COLOR, oldColor, color));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue)

Example 4 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class MBrickletLEDStripImpl method setColor.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setColor(HSBValue newColor) {
    HSBValue oldColor = color;
    color = newColor;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MBRICKLET_LED_STRIP__COLOR, oldColor, color));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue)

Example 5 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class TinkerforgeBinding method postUpdate.

private void postUpdate(String uid, String subId, TinkerforgeValue sensorValue) {
    // TODO undef handling
    logger.trace("postUpdate called for uid {} subid {}", uid, subId);
    Map<String, TinkerforgeBindingProvider> providerMap = getBindingProviders(uid, subId);
    if (providerMap.size() == 0) {
        logger.debug("{} found no item for uid {}, subid {}", LoggerConstants.TFMODELUPDATE, uid, subId);
    }
    for (Entry<String, TinkerforgeBindingProvider> entry : providerMap.entrySet()) {
        String itemName = entry.getKey();
        TinkerforgeBindingProvider provider = entry.getValue();
        Class<? extends Item> itemType = provider.getItemType(itemName);
        State value = UnDefType.UNDEF;
        if (sensorValue instanceof DecimalValue) {
            if (itemType.isAssignableFrom(NumberItem.class) || itemType.isAssignableFrom(StringItem.class)) {
                value = DecimalType.valueOf(String.valueOf(sensorValue));
                logger.trace("found item to update for DecimalValue {}", itemName);
            } else if (itemType.isAssignableFrom(ContactItem.class)) {
                value = sensorValue.equals(DecimalValue.ZERO) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
            } else if (itemType.isAssignableFrom(SwitchItem.class)) {
                value = sensorValue.equals(DecimalValue.ZERO) ? OnOffType.OFF : OnOffType.ON;
            } else {
                logger.trace("no update for DecimalValue for item {}", itemName);
                continue;
            }
        } else if (sensorValue instanceof HighLowValue) {
            if (itemType.isAssignableFrom(NumberItem.class) || itemType.isAssignableFrom(StringItem.class)) {
                value = sensorValue == HighLowValue.HIGH ? DecimalType.valueOf("1") : DecimalType.valueOf("0");
            } else if (itemType.isAssignableFrom(ContactItem.class)) {
                value = sensorValue == HighLowValue.HIGH ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
            } else if (itemType.isAssignableFrom(SwitchItem.class)) {
                value = sensorValue == HighLowValue.HIGH ? OnOffType.ON : OnOffType.OFF;
            } else {
                continue;
            }
        } else if (sensorValue instanceof OnOffValue) {
            if (itemType.isAssignableFrom(NumberItem.class) || itemType.isAssignableFrom(StringItem.class)) {
                value = sensorValue == OnOffValue.ON ? DecimalType.valueOf("1") : DecimalType.valueOf("0");
            } else if (itemType.isAssignableFrom(ContactItem.class)) {
                value = sensorValue == OnOffValue.ON ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
            } else if (itemType.isAssignableFrom(SwitchItem.class)) {
                value = sensorValue == OnOffValue.ON ? OnOffType.ON : OnOffType.OFF;
            } else {
                continue;
            }
        } else if (sensorValue instanceof PercentValue) {
            if (itemType.isAssignableFrom(SwitchItem.class)) {
                value = ((PercentValue) sensorValue).toBigDecimal().compareTo(BigDecimal.ZERO) == 1 ? OnOffType.ON : OnOffType.OFF;
                logger.debug("switch found {}", itemName);
            } else if (itemType.isAssignableFrom(RollershutterItem.class) || itemType.isAssignableFrom(DimmerItem.class)) {
                value = new PercentType(((PercentValue) sensorValue).toBigDecimal());
                logger.debug("Rollershutter or dimmer found {} {}", itemName);
            } else if (itemType.isAssignableFrom(ContactItem.class)) {
                value = ((PercentValue) sensorValue).toBigDecimal().compareTo(BigDecimal.ZERO) == -1 ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
                logger.debug("contact found {}", itemName);
            } else {
                continue;
            }
        } else if (sensorValue instanceof DirectionValue) {
            if (itemType.isAssignableFrom(RollershutterItem.class)) {
                value = sensorValue == DirectionValue.RIGHT ? UpDownType.UP : UpDownType.DOWN;
                logger.trace("found item to update for UpDownValue {}", itemName);
            } else {
                continue;
            }
        } else if (sensorValue instanceof HSBValue) {
            if (itemType.isAssignableFrom(ColorItem.class)) {
                logger.trace("found item to update for HSBValue {}", itemName);
                value = ((HSBValue) sensorValue).getHsbValue();
            }
        } else if (sensorValue == UnDefValue.UNDEF || sensorValue == null) {
            value = UnDefType.UNDEF;
        }
        eventPublisher.postUpdate(itemName, value);
        logger.debug("{} postupdate: found sensorValue: {} for item {}", LoggerConstants.TFMODELUPDATE, sensorValue, itemName);
    }
}
Also used : OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) PercentValue(org.openhab.binding.tinkerforge.internal.types.PercentValue) DirectionValue(org.openhab.binding.tinkerforge.internal.types.DirectionValue) ContactItem(org.openhab.core.library.items.ContactItem) ColorItem(org.openhab.core.library.items.ColorItem) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) NumberItem(org.openhab.core.library.items.NumberItem) TinkerforgeBindingProvider(org.openhab.binding.tinkerforge.TinkerforgeBindingProvider) DecimalValue(org.openhab.binding.tinkerforge.internal.types.DecimalValue) State(org.openhab.core.types.State) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DimmerItem(org.openhab.core.library.items.DimmerItem) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue) HighLowValue(org.openhab.binding.tinkerforge.internal.types.HighLowValue) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

HSBValue (org.openhab.binding.tinkerforge.internal.types.HSBValue)7 NotConnectedException (com.tinkerforge.NotConnectedException)3 TimeoutException (com.tinkerforge.TimeoutException)3 Color (java.awt.Color)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 HashMap (java.util.HashMap)2 BrickletColor (com.tinkerforge.BrickletColor)1 TinkerforgeBindingProvider (org.openhab.binding.tinkerforge.TinkerforgeBindingProvider)1 ColorColor (org.openhab.binding.tinkerforge.internal.model.ColorColor)1 MBrickletColor (org.openhab.binding.tinkerforge.internal.model.MBrickletColor)1 LedList (org.openhab.binding.tinkerforge.internal.tools.LedList)1 DecimalValue (org.openhab.binding.tinkerforge.internal.types.DecimalValue)1 DirectionValue (org.openhab.binding.tinkerforge.internal.types.DirectionValue)1 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)1 OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)1 PercentValue (org.openhab.binding.tinkerforge.internal.types.PercentValue)1 ColorItem (org.openhab.core.library.items.ColorItem)1 ContactItem (org.openhab.core.library.items.ContactItem)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1