Search in sources :

Example 6 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class TradfriGatewayHandler method initialize.

@Override
public void initialize() {
    TradfriGatewayConfig configuration = getConfigAs(TradfriGatewayConfig.class);
    if (isNullOrEmpty(configuration.host)) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Host must be specified in the configuration!");
        return;
    }
    if (isNullOrEmpty(configuration.code)) {
        if (isNullOrEmpty(configuration.identity) || isNullOrEmpty(configuration.preSharedKey)) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Either security code or identity and pre-shared key must be provided in the configuration!");
            return;
        } else {
            establishConnection();
        }
    } else {
        if (isOldFirmware()) {
            /*
                 * older firmware - fall back to authentication with security code
                 * in this case the Thing configuration will not be persisted
                 */
            logger.warn("Gateway with old firmware - please consider upgrading to the latest version.");
            Configuration editedConfig = editConfiguration();
            editedConfig.put(TradfriBindingConstants.GATEWAY_CONFIG_IDENTITY, "");
            editedConfig.put(TradfriBindingConstants.GATEWAY_CONFIG_PRE_SHARED_KEY, configuration.code);
            updateConfiguration(editedConfig);
            establishConnection();
        } else {
            // Running async operation to retrieve new <'identity','key'> pair
            scheduler.execute(() -> {
                boolean success = obtainIdentityAndPreSharedKey();
                if (success) {
                    establishConnection();
                }
            });
        }
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) TradfriGatewayConfig(org.eclipse.smarthome.binding.tradfri.internal.config.TradfriGatewayConfig)

Example 7 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class WemoMakerHandler method onUpdate.

private synchronized void onUpdate() {
    if (service.isRegistered(this)) {
        if (refreshJob == null || refreshJob.isCancelled()) {
            Configuration config = getThing().getConfiguration();
            int refreshInterval = DEFAULT_REFRESH_INTERVAL;
            Object refreshConfig = config.get("refresh");
            if (refreshConfig != null) {
                refreshInterval = ((BigDecimal) refreshConfig).intValue();
            }
            refreshJob = scheduler.scheduleWithFixedDelay(refreshRunnable, 0, refreshInterval, TimeUnit.SECONDS);
        }
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 8 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class WemoMakerHandler method initialize.

@Override
public void initialize() {
    Configuration configuration = getConfig();
    if (configuration.get("udn") != null) {
        logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get("udn"));
        onUpdate();
        updateStatus(ThingStatus.ONLINE);
    } else {
        logger.debug("Cannot initalize WemoMakerHandler. UDN not set.");
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 9 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class YahooWeatherHandler method initialize.

@Override
public void initialize() {
    logger.debug("Initializing YahooWeather handler.");
    Configuration config = getThing().getConfiguration();
    location = (BigDecimal) config.get(LOCATION_PARAM);
    try {
        refresh = (BigDecimal) config.get("refresh");
    } catch (Exception e) {
        logger.debug("Cannot set refresh parameter.", e);
    }
    if (refresh == null) {
        // let's go for the default
        refresh = new BigDecimal(60);
    }
    cache.put(CACHE_KEY_CONFIG, () -> connection.getResponseFromQuery("SELECT location FROM weather.forecast WHERE woeid = " + location.toPlainString()));
    cache.put(CACHE_KEY_WEATHER, () -> connection.getResponseFromQuery("SELECT * FROM weather.forecast WHERE u = 'c' AND woeid = " + location.toPlainString()));
    startAutomaticRefresh();
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BigDecimal(java.math.BigDecimal)

Example 10 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class WemoBridgeHandler method initialize.

@Override
public void initialize() {
    logger.debug("Initializing WemoBridgeHandler");
    Configuration configuration = getConfig();
    if (configuration.get(UDN) != null) {
        logger.trace("Initializing WemoBridgeHandler for UDN '{}'", configuration.get(UDN));
        updateStatus(ThingStatus.ONLINE);
    } else {
        logger.debug("Cannot initalize WemoBridgeHandler. UDN not set.");
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

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