use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class GenericItemChannelLinkProviderJavaTest method testNoAmnesia.
@SuppressWarnings("unchecked")
@Test
public void testNoAmnesia() throws Exception {
GenericItemChannelLinkProvider provider = new GenericItemChannelLinkProvider();
provider.addProviderChangeListener(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "Number", ITEM, CHANNEL, new Configuration());
provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
assertThat(provider.getAll().size(), is(1));
assertThat(provider.getAll().iterator().next().toString(), is(LINK));
verify(listener, only()).added(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
reset(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "Number", ITEM, CHANNEL, new Configuration());
provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
assertThat(provider.getAll().size(), is(1));
assertThat(provider.getAll().iterator().next().toString(), is(LINK));
verify(listener, only()).updated(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
reset(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
assertThat(provider.getAll().size(), is(0));
verify(listener, only()).removed(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class MagicServiceImpl method modified.
@Modified
public void modified(Map<String, Object> properties) {
MagicServiceConfig config = new Configuration(properties).as(MagicServiceConfig.class);
logger.debug("Magic Service has been modified: {}", config);
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class DeviceHandler method loadSensorChannels.
private void loadSensorChannels() {
if (device != null && device.isPresent()) {
// load sensor priorities into the device
boolean configChanged = false;
Configuration config = getThing().getConfiguration();
logger.debug("Add sensor priorities to the device");
String activePowerPrio = Config.REFRESH_PRIORITY_NEVER;
if (config.get(DigitalSTROMBindingConstants.ACTIVE_POWER_REFRESH_PRIORITY) != null) {
activePowerPrio = config.get(DigitalSTROMBindingConstants.ACTIVE_POWER_REFRESH_PRIORITY).toString();
} else {
config.put(DigitalSTROMBindingConstants.ACTIVE_POWER_REFRESH_PRIORITY, Config.REFRESH_PRIORITY_NEVER);
configChanged = true;
}
// in standby any more.
if (OutputModeEnum.WIPE.equals(device.getOutputMode()) && activePowerPrio.equals(Config.REFRESH_PRIORITY_NEVER)) {
config.put(DigitalSTROMBindingConstants.ACTIVE_POWER_REFRESH_PRIORITY, Config.REFRESH_PRIORITY_LOW);
configChanged = true;
}
String outputCurrentPrio = Config.REFRESH_PRIORITY_NEVER;
if (config.get(DigitalSTROMBindingConstants.OUTPUT_CURRENT_REFRESH_PRIORITY) != null) {
outputCurrentPrio = config.get(DigitalSTROMBindingConstants.OUTPUT_CURRENT_REFRESH_PRIORITY).toString();
} else {
config.put(DigitalSTROMBindingConstants.OUTPUT_CURRENT_REFRESH_PRIORITY, Config.REFRESH_PRIORITY_NEVER);
configChanged = true;
}
String electricMeterPrio = Config.REFRESH_PRIORITY_NEVER;
if (config.get(DigitalSTROMBindingConstants.ELECTRIC_METER_REFRESH_PRIORITY) != null) {
electricMeterPrio = config.get(DigitalSTROMBindingConstants.ELECTRIC_METER_REFRESH_PRIORITY).toString();
} else {
config.put(DigitalSTROMBindingConstants.ELECTRIC_METER_REFRESH_PRIORITY, Config.REFRESH_PRIORITY_NEVER);
configChanged = true;
}
if (configChanged) {
super.updateConfiguration(config);
configChanged = false;
}
device.setSensorDataRefreshPriority(activePowerPrio, electricMeterPrio, outputCurrentPrio);
logger.debug("add sensor prioritys: active power = {}, output current = {}, electric meter = {} to device with id {}", activePowerPrio, outputCurrentPrio, electricMeterPrio, device.getDSID());
// check and load sensor channels of the thing
checkSensorChannel();
}
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class BridgeHandler method onConnectionStateChange.
@Override
public void onConnectionStateChange(String newConnectionState) {
switch(newConnectionState) {
case CONNECTION_LOST:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "The connection to the digitalSTROM-Server cannot be established.");
startReconnectTracker();
return;
case CONNECTION_RESUMED:
if (connectionTimeoutCounter > 0) {
if (connMan.checkConnection()) {
restartServices();
setStatus(ThingStatus.ONLINE);
}
}
// reset connection timeout counter
connectionTimeoutCounter = 0;
return;
case APPLICATION_TOKEN_GENERATED:
if (connMan != null) {
Configuration config = this.getConfig();
if (config != null) {
config.remove(USER_NAME);
config.remove(PASSWORD);
config.put(APPLICATION_TOKEN, connMan.getApplicationToken());
this.updateConfiguration(config);
}
}
return;
default:
return;
}
}
use of org.eclipse.smarthome.config.core.Configuration 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;
}
Aggregations