use of org.openhab.binding.tinkerforge.internal.config.ConfigurationException 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);
}
}
use of org.openhab.binding.tinkerforge.internal.config.ConfigurationException in project openhab1-addons by openhab.
the class MBrickletThermocoupleImpl method enable.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
public void enable() {
List<Short> possibleAveragingValues = Arrays.asList(new Short[] { 1, 2, 4, 8, 16 });
List<String> possibleTypeValues = Arrays.asList(new String[] { "B", "E", "J", "K", "N", "R", "S", "T", "G8", "G32" });
List<String> possibleFilterValues = Arrays.asList(new String[] { "50", "60" });
short averaging = BrickletThermocouple.AVERAGING_1;
short thermocoupleTypeId = BrickletThermocouple.TYPE_K;
short filterId = BrickletThermocouple.FILTER_OPTION_50HZ;
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("averaging"))) {
Short averagingConfig = tfConfig.getAveraging();
if (!possibleAveragingValues.contains(averagingConfig)) {
logger.error("invalid averaging configuration {}", averagingConfig);
throw new ConfigurationException("invalid averaging configuration " + averagingConfig);
}
averaging = averagingConfig;
}
if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("thermocoupleType"))) {
String thermocoupleType = tfConfig.getThermocoupleType();
if (!possibleTypeValues.contains(thermocoupleType)) {
logger.error("invalid thermocoupleType {}", thermocoupleType);
throw new ConfigurationException("invalid thermocoupleType" + thermocoupleType);
}
thermocoupleTypeId = getTypeId(thermocoupleType);
}
if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("filter"))) {
String filterConfig = tfConfig.getFilter();
if (!possibleFilterValues.contains(filterConfig)) {
logger.error("invalid filter configuration {}", filterConfig);
throw new ConfigurationException("invalid filter configuration" + filterConfig);
}
filterId = filterConfig.equals("50") ? BrickletThermocouple.FILTER_OPTION_50HZ : BrickletThermocouple.FILTER_OPTION_60HZ;
}
}
try {
tinkerforgeDevice = new BrickletThermocouple(getUid(), getIpConnection());
tinkerforgeDevice.setConfiguration(averaging, thermocoupleTypeId, filterId);
tinkerforgeDevice.setTemperatureCallbackPeriod(getCallbackPeriod());
listener = new TemperatureListener();
tinkerforgeDevice.addTemperatureListener(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);
}
}
Aggregations