Search in sources :

Example 1 with BrickletAmbientLightV2

use of com.tinkerforge.BrickletAmbientLightV2 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 2 with BrickletAmbientLightV2

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

the class MBrickletAmbientLightV2Impl method setTinkerforgeDevice.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     *
     * @generated
     */
@Override
public void setTinkerforgeDevice(BrickletAmbientLightV2 newTinkerforgeDevice) {
    BrickletAmbientLightV2 oldTinkerforgeDevice = tinkerforgeDevice;
    tinkerforgeDevice = newTinkerforgeDevice;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MBRICKLET_AMBIENT_LIGHT_V2__TINKERFORGE_DEVICE, oldTinkerforgeDevice, tinkerforgeDevice));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) BrickletAmbientLightV2(com.tinkerforge.BrickletAmbientLightV2) MBrickletAmbientLightV2(org.openhab.binding.tinkerforge.internal.model.MBrickletAmbientLightV2)

Aggregations

BrickletAmbientLightV2 (com.tinkerforge.BrickletAmbientLightV2)2 MBrickletAmbientLightV2 (org.openhab.binding.tinkerforge.internal.model.MBrickletAmbientLightV2)2 NotConnectedException (com.tinkerforge.NotConnectedException)1 TimeoutException (com.tinkerforge.TimeoutException)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 ConfigurationException (org.openhab.binding.tinkerforge.internal.config.ConfigurationException)1