use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.config.Config in project smarthome by eclipse.
the class BridgeHandler method initialize.
@Override
public void initialize() {
logger.debug("Initializing digitalSTROM-BridgeHandler");
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING, "Checking configuration...");
// Start an extra thread to readout the configuration and check the connection, because it takes sometimes more
// than 5000 milliseconds and the handler will suspend (ThingStatus.UNINITIALIZED).
Config config = loadAndCheckConfig();
if (config != null) {
logger.debug("{}", config.toString());
scheduler.execute(new Initializer(this, config));
}
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.config.Config in project smarthome by eclipse.
the class BridgeHandler method loadAndCheckConfig.
private Config loadAndCheckConfig() {
Configuration thingConfig = super.getConfig();
Config config = loadAndCheckConnectionData(thingConfig);
if (config == null) {
return null;
}
logger.debug("Loading configuration");
ArrayList<String> numberExc = new ArrayList<String>();
// Parameters can't be null, because of an existing default value.
if (thingConfig.get(DigitalSTROMBindingConstants.SENSOR_DATA_UPDATE_INTERVAL) instanceof BigDecimal) {
config.setSensordataRefreshInterval(((BigDecimal) thingConfig.get(DigitalSTROMBindingConstants.SENSOR_DATA_UPDATE_INTERVAL)).intValue() * 1000);
} else {
numberExc.add("\"Sensor update interval\" ( " + thingConfig.get(DigitalSTROMBindingConstants.SENSOR_DATA_UPDATE_INTERVAL) + ")");
}
if (thingConfig.get(DigitalSTROMBindingConstants.TOTAL_POWER_UPDATE_INTERVAL) instanceof BigDecimal) {
config.setTotalPowerUpdateInterval(((BigDecimal) thingConfig.get(DigitalSTROMBindingConstants.TOTAL_POWER_UPDATE_INTERVAL)).intValue() * 1000);
} else {
numberExc.add("\"Total power update interval\" (" + thingConfig.get(DigitalSTROMBindingConstants.TOTAL_POWER_UPDATE_INTERVAL) + ")");
}
if (thingConfig.get(DigitalSTROMBindingConstants.SENSOR_WAIT_TIME) instanceof BigDecimal) {
config.setSensorReadingWaitTime(((BigDecimal) thingConfig.get(DigitalSTROMBindingConstants.SENSOR_WAIT_TIME)).intValue() * 1000);
} else {
numberExc.add("\"Wait time sensor reading\" (" + thingConfig.get(DigitalSTROMBindingConstants.SENSOR_WAIT_TIME) + ")");
}
if (thingConfig.get(DigitalSTROMBindingConstants.DEFAULT_TRASH_DEVICE_DELETE_TIME_KEY) instanceof BigDecimal) {
config.setTrashDeviceDeleteTime(((BigDecimal) thingConfig.get(DigitalSTROMBindingConstants.DEFAULT_TRASH_DEVICE_DELETE_TIME_KEY)).intValue());
} else {
numberExc.add("\"Days to be slaked trash bin devices\" (" + thingConfig.get(DigitalSTROMBindingConstants.DEFAULT_TRASH_DEVICE_DELETE_TIME_KEY) + ")");
}
if (!numberExc.isEmpty()) {
String excText = "The field ";
for (int i = 0; i < numberExc.size(); i++) {
excText = excText + numberExc.get(i);
if (i < numberExc.size() - 2) {
excText = excText + ", ";
} else if (i < numberExc.size() - 1) {
excText = excText + " and ";
}
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, excText + " have to be a number.");
return null;
}
if (StringUtils.isNotBlank(getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT))) {
config.setCert(getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT));
}
return config;
}
use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.config.Config in project smarthome by eclipse.
the class ConnectionManagerImpl method init.
private void init(String hostAddress, int connectionTimeout, int readTimeout, String username, String password, String applicationToken, boolean acceptAllCerts) {
config = new Config(hostAddress, username, password, applicationToken);
if (connectionTimeout >= 0) {
config.setConnectionTimeout(connectionTimeout);
}
if (readTimeout >= 0) {
config.setReadTimeout(readTimeout);
}
init(config, acceptAllCerts);
}
Aggregations