]> git.basschouten.com Git - openhab-addons.git/blob
ef5b22b0a9058dd425e502eb0a26e3227af7251a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.tapocontrol.internal.structures;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.config.core.Configuration;
17 import org.openhab.core.thing.Thing;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link TapoBridgeConfiguration} class contains fields mapping bridge configuration parameters.
23  *
24  * @author Christian Wild - Initial contribution
25  */
26
27 @NonNullByDefault
28 public final class TapoBridgeConfiguration {
29     private final Logger logger = LoggerFactory.getLogger(TapoBridgeConfiguration.class);
30
31     /* THING CONFIGUTATION PROPERTYS */
32     public static final String CONFIG_EMAIL = "username";
33     public static final String CONFIG_PASS = "password";
34     public static final String CONFIG_DEVICE_IP = "ipAddress";
35     public static final String CONFIG_UPDATE_INTERVAL = "pollingInterval";
36     public static final String CONFIG_DISCOVERY_CLOUD = "cloudDiscovery";
37     public static final String CONFIG_DISCOVERY_INTERVAL = "discoveryInterval";
38
39     /* DEFAULT & FIXED CONFIGURATIONS */
40     public static final Integer CONFIG_CLOUD_FIXED_INTERVAL = 1440;
41
42     /* thing configuration parameter. */
43     public String username = "";
44     public String password = "";
45     public Boolean cloudDiscoveryEnabled = false;
46     public Boolean udpDiscoveryEnabled = false;
47     public Integer cloudReconnectIntervalM = CONFIG_CLOUD_FIXED_INTERVAL;
48     public Integer discoveryIntervalM = 30;
49
50     private Thing bridge;
51
52     /**
53      * Create settings
54      * 
55      * @param thing BridgeThing
56      */
57     public TapoBridgeConfiguration(Thing thing) {
58         this.bridge = thing;
59         loadSettings();
60     }
61
62     /**
63      * LOAD SETTINGS
64      */
65     public void loadSettings() {
66         try {
67             Configuration config = this.bridge.getConfiguration();
68             username = config.get(CONFIG_EMAIL).toString();
69             password = config.get(CONFIG_PASS).toString();
70             cloudDiscoveryEnabled = Boolean.parseBoolean(config.get(CONFIG_DISCOVERY_CLOUD).toString());
71             discoveryIntervalM = Integer.valueOf(config.get(CONFIG_DISCOVERY_INTERVAL).toString());
72         } catch (Exception e) {
73             logger.warn("{} error reading configuration: '{}'", bridge.getUID(), e.getMessage());
74         }
75     }
76 }