Search in sources :

Example 1 with MystromClient

use of org.openhab.binding.mystromecopower.internal.api.MystromClient in project openhab1-addons by openhab.

the class MyStromEcoPowerBinding method updated.

/**
     * {@inheritDoc}
     */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        // to override the default refresh interval one has to add a
        // parameter to openhab.cfg like
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }
        // read further config parameters here ...
        // read user name
        String userName = (String) config.get("userName");
        if (StringUtils.isNotBlank(userName)) {
            this.userName = userName;
        } else {
            throw new ConfigurationException("userName", "The userName to connect to myStrom must be specified in config file");
        }
        String password = (String) config.get("password");
        if (StringUtils.isNotBlank(password)) {
            this.password = password;
        } else {
            throw new ConfigurationException("password", "The password to connect to myStrom must be specified in config file");
        }
        if (this.devMode) {
            this.mystromClient = new MockMystromClient();
        } else {
            this.mystromClient = new MystromClient(this.userName, this.password, logger);
        }
        if (ChangeStateJob.MystromClient == null) {
            ChangeStateJob.MystromClient = this.mystromClient;
        }
        setProperlyConfigured(true);
        // do a discovery of all mystrom eco power to get id of devices
        try {
            this.mystromDiscovery();
        } catch (IOException e) {
            logger.error("Error doing discovery of your devices", e);
        }
    }
}
Also used : MockMystromClient(org.openhab.binding.mystromecopower.internal.api.mock.MockMystromClient) IMystromClient(org.openhab.binding.mystromecopower.internal.api.IMystromClient) MystromClient(org.openhab.binding.mystromecopower.internal.api.MystromClient) ConfigurationException(org.osgi.service.cm.ConfigurationException) MockMystromClient(org.openhab.binding.mystromecopower.internal.api.mock.MockMystromClient) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 IMystromClient (org.openhab.binding.mystromecopower.internal.api.IMystromClient)1 MystromClient (org.openhab.binding.mystromecopower.internal.api.MystromClient)1 MockMystromClient (org.openhab.binding.mystromecopower.internal.api.mock.MockMystromClient)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1