Search in sources :

Example 6 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class MBrickletColorImpl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("gain"))) {
            Short gainConfig = tfConfig.getGain();
            switch(gainConfig) {
                case 0:
                    this.gain = 0;
                    break;
                case 1:
                    this.gain = 1;
                    break;
                case 2:
                    this.gain = 2;
                    break;
                default:
                    logger.error("invalid gain value {}; using default gain", gainConfig);
                    break;
            }
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("integrationTime"))) {
            Short integrationTimeConfig = tfConfig.getIntegrationTime();
            switch(integrationTimeConfig) {
                case 0:
                    this.integrationTime = 0;
                    break;
                case 1:
                    this.integrationTime = 1;
                    break;
                case 2:
                    this.integrationTime = 2;
                    break;
                case 3:
                    this.integrationTime = 3;
                    break;
                case 4:
                    this.integrationTime = 4;
                    break;
                default:
                    logger.error("invalid integrationTime value {}; using default integrationTime", integrationTimeConfig);
                    break;
            }
        }
    }
    try {
        tinkerforgeDevice = new BrickletColor(getUid(), getIpConnection());
        tinkerforgeDevice.setConfig(gain, integrationTime);
    } 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) MBrickletColor(org.openhab.binding.tinkerforge.internal.model.MBrickletColor) BrickletColor(com.tinkerforge.BrickletColor) TimeoutException(com.tinkerforge.TimeoutException)

Example 7 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class MBrickletAmbientLightImpl method enable.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
            setThreshold(tfConfig.getThreshold());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
            setCallbackPeriod(tfConfig.getCallbackPeriod());
        }
    }
    tinkerforgeDevice = new BrickletAmbientLight(uid, ipConnection);
    // false);
    try {
        tinkerforgeDevice.setIlluminanceCallbackPeriod(callbackPeriod);
        listener = new IlluminanceListener();
        tinkerforgeDevice.addIlluminanceListener(listener);
        fetchSensorValue();
    } 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) BrickletAmbientLight(com.tinkerforge.BrickletAmbientLight) MBrickletAmbientLight(org.openhab.binding.tinkerforge.internal.model.MBrickletAmbientLight) TimeoutException(com.tinkerforge.TimeoutException)

Example 8 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class MBrickletAmbientLightV2Impl method enable.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void enable() {
    List<Integer> possibleIlluminanceValues = Arrays.asList(new Integer[] { 0, 1, 2, 3, 4, 5, 6 });
    List<Integer> possibleIntegrationTimeValues = Arrays.asList(new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7 });
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
            logger.debug("threshold {}", tfConfig.getThreshold());
            setThreshold(tfConfig.getThreshold());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
            logger.debug("callbackPeriod {}", tfConfig.getCallbackPeriod());
            setCallbackPeriod(tfConfig.getCallbackPeriod());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("illuminanceRange"))) {
            short illuminanceRange = tfConfig.getIlluminanceRange();
            logger.debug("illuminanceRange {}", illuminanceRange);
            if (!possibleIlluminanceValues.contains(illuminanceRange)) {
                logger.error("invalid illuminanceRange value: {}", illuminanceRange);
                throw new ConfigurationException("invalid illuminanceRange value: " + illuminanceRange);
            }
            setIlluminanceRange(illuminanceRange);
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("integrationTime"))) {
            short integrationTime = tfConfig.getIntegrationTime();
            logger.debug("integrationTime {}", integrationTime);
            if (!possibleIntegrationTimeValues.contains(integrationTime)) {
                logger.error("invalid integrationTime value: {}", integrationTime);
                throw new ConfigurationException("invalid integrationTime value: " + integrationTime);
            }
            setIntegrationTime(integrationTime);
        }
    }
    tinkerforgeDevice = new BrickletAmbientLightV2(getUid(), getIpConnection());
    try {
        tinkerforgeDevice.setIlluminanceCallbackPeriod(callbackPeriod);
        tinkerforgeDevice.setConfiguration(getIlluminanceRange(), getIntegrationTime());
        listener = new IlluminanceListener();
        tinkerforgeDevice.addIlluminanceListener(listener);
        fetchSensorValue();
    } 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) ConfigurationException(org.openhab.binding.tinkerforge.internal.config.ConfigurationException) BrickletAmbientLightV2(com.tinkerforge.BrickletAmbientLightV2) MBrickletAmbientLightV2(org.openhab.binding.tinkerforge.internal.model.MBrickletAmbientLightV2) TimeoutException(com.tinkerforge.TimeoutException)

Example 9 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class MBrickletAnalogInV2Impl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
            setThreshold(tfConfig.getThreshold());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
            setCallbackPeriod(tfConfig.getCallbackPeriod());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("movingAverage"))) {
            logger.debug("{} setting movingAverage: {}", LoggerConstants.TFINIT, tfConfig.getMovingAverage());
            setMovingAverage(tfConfig.getMovingAverage());
        }
    }
    try {
        tinkerforgeDevice = new BrickletAnalogInV2(getUid(), getIpConnection());
        tinkerforgeDevice.setVoltageCallbackPeriod(getCallbackPeriod());
        tinkerforgeDevice.setMovingAverage(getMovingAverage());
        listener = new VoltageListener();
        tinkerforgeDevice.addVoltageListener(listener);
        fetchSensorValue();
    } 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 : MBrickletAnalogInV2(org.openhab.binding.tinkerforge.internal.model.MBrickletAnalogInV2) BrickletAnalogInV2(com.tinkerforge.BrickletAnalogInV2) NotConnectedException(com.tinkerforge.NotConnectedException) TimeoutException(com.tinkerforge.TimeoutException)

Example 10 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class MBrickletAmbientLightImpl method fetchSensorValue.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    try {
        int illuminance = tinkerforgeDevice.getIlluminance();
        DecimalValue value = Tools.calculate10(illuminance);
        setSensorValue(value);
    } 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 : DecimalValue(org.openhab.binding.tinkerforge.internal.types.DecimalValue) NotConnectedException(com.tinkerforge.NotConnectedException) TimeoutException(com.tinkerforge.TimeoutException)

Aggregations

NotConnectedException (com.tinkerforge.NotConnectedException)107 TimeoutException (com.tinkerforge.TimeoutException)107 DecimalValue (org.openhab.binding.tinkerforge.internal.types.DecimalValue)36 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)14 OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)8 BigDecimal (java.math.BigDecimal)4 Color (java.awt.Color)3 BrickServo (com.tinkerforge.BrickServo)2 BrickletColor (com.tinkerforge.BrickletColor)2 LEDState (com.tinkerforge.BrickletDualButton.LEDState)2 BrickletIO16 (com.tinkerforge.BrickletIO16)2 BrickletIO4 (com.tinkerforge.BrickletIO4)2 Position (com.tinkerforge.BrickletJoystick.Position)2 BrickletMultiTouch (com.tinkerforge.BrickletMultiTouch)2 BrickletTemperatureIR (com.tinkerforge.BrickletTemperatureIR)2 HashMap (java.util.HashMap)2 ConfigurationException (org.openhab.binding.tinkerforge.internal.config.ConfigurationException)2 MBrickletIO16 (org.openhab.binding.tinkerforge.internal.model.MBrickletIO16)2 MBrickletIO4 (org.openhab.binding.tinkerforge.internal.model.MBrickletIO4)2 LinePositionText (org.openhab.binding.tinkerforge.internal.tools.LinePositionText)2