Search in sources :

Example 6 with OnOffValue

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

the class MServoImpl method setSwitchState.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setSwitchState(OnOffValue newSwitchState) {
    OnOffValue oldSwitchState = switchState;
    switchState = newSwitchState;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MSERVO__SWITCH_STATE, oldSwitchState, switchState));
}
Also used : OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 7 with OnOffValue

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

the class MServoImpl method fetchSensorValue.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    try {
        short position = getMbrick().getTinkerforgeDevice().getPosition(servoNum);
        DecimalValue newValue = Tools.calculate(position);
        setSensorValue(newValue);
        OnOffValue newSwitchState = newValue.onOffValue(0);
        logger.trace("new switchstate {} new value {}", newSwitchState, newValue);
        setSwitchState(newSwitchState);
    } 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 : OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) DecimalValue(org.openhab.binding.tinkerforge.internal.types.DecimalValue) NotConnectedException(com.tinkerforge.NotConnectedException) TimeoutException(com.tinkerforge.TimeoutException)

Example 8 with OnOffValue

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

the class MLCD20x4BacklightImpl method setSwitchState.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setSwitchState(OnOffValue newSwitchState) {
    OnOffValue oldSwitchState = switchState;
    switchState = newSwitchState;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MLCD2_0X4_BACKLIGHT__SWITCH_STATE, oldSwitchState, switchState));
}
Also used : OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 9 with OnOffValue

use of org.openhab.binding.tinkerforge.internal.types.OnOffValue 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)

Example 10 with OnOffValue

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

the class RemoteSwitchAImpl method setSwitchState.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setSwitchState(OnOffValue newSwitchState) {
    OnOffValue oldSwitchState = switchState;
    switchState = newSwitchState;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.REMOTE_SWITCH_A__SWITCH_STATE, oldSwitchState, switchState));
}
Also used : OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)26 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)15 NotConnectedException (com.tinkerforge.NotConnectedException)8 TimeoutException (com.tinkerforge.TimeoutException)8 DecimalValue (org.openhab.binding.tinkerforge.internal.types.DecimalValue)3 TinkerforgeBindingProvider (org.openhab.binding.tinkerforge.TinkerforgeBindingProvider)2 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)2 PercentType (org.openhab.core.library.types.PercentType)2 ButtonState (com.tinkerforge.BrickletDualButton.ButtonState)1 State (com.tinkerforge.BrickletDualRelay.State)1 DigitalActor (org.openhab.binding.tinkerforge.internal.model.DigitalActor)1 DimmableActor (org.openhab.binding.tinkerforge.internal.model.DimmableActor)1 MBaseDevice (org.openhab.binding.tinkerforge.internal.model.MBaseDevice)1 MSwitchActor (org.openhab.binding.tinkerforge.internal.model.MSwitchActor)1 MTextActor (org.openhab.binding.tinkerforge.internal.model.MTextActor)1 MoveActor (org.openhab.binding.tinkerforge.internal.model.MoveActor)1 NumberActor (org.openhab.binding.tinkerforge.internal.model.NumberActor)1 PercentTypeActor (org.openhab.binding.tinkerforge.internal.model.PercentTypeActor)1 ProgrammableColorActor (org.openhab.binding.tinkerforge.internal.model.ProgrammableColorActor)1 ProgrammableSwitchActor (org.openhab.binding.tinkerforge.internal.model.ProgrammableSwitchActor)1