Search in sources :

Example 71 with Configuration

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))));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) GenericItemChannelLinkProvider(org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 72 with Configuration

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);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Modified(org.osgi.service.component.annotations.Modified)

Example 73 with Configuration

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();
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 74 with Configuration

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;
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 75 with Configuration

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;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Config(org.eclipse.smarthome.binding.digitalstrom.internal.lib.config.Config) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Aggregations

Configuration (org.eclipse.smarthome.config.core.Configuration)119 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 ArrayList (java.util.ArrayList)18 Thing (org.eclipse.smarthome.core.thing.Thing)18 Action (org.eclipse.smarthome.automation.Action)16 Trigger (org.eclipse.smarthome.automation.Trigger)16 Rule (org.eclipse.smarthome.automation.Rule)15 Before (org.junit.Before)14 Condition (org.eclipse.smarthome.automation.Condition)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 HashMap (java.util.HashMap)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)8 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 BigDecimal (java.math.BigDecimal)6 Consumes (javax.ws.rs.Consumes)6 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)6