]> git.basschouten.com Git - openhab-addons.git/blob
13b039da30ce5e06394a229c9a29133234aab470
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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_CLOUD_UPDATE_INTERVAL = "cloudReconnect";
37     public static final String CONFIG_DISCOVERY_CLOUD = "cloudDiscovery";
38     public static final String CONFIG_DISCOVERY_UDP = "udpDiscovery";
39     public static final String CONFIG_DISCOVERY_INTERVAL = "discoveryInterval";
40
41     /* thing configuration parameter. */
42     public String username = "";
43     public String password = "";
44     public Boolean cloudDiscoveryEnabled = false;
45     public Boolean udpDiscoveryEnabled = false;
46     public Integer cloudReconnectIntervalM = 1440;
47     public Integer discoveryIntervalM = 30;
48
49     private Thing bridge;
50
51     /**
52      * Create settings
53      * 
54      * @param thing BridgeThing
55      */
56     public TapoBridgeConfiguration(Thing thing) {
57         this.bridge = thing;
58         loadSettings();
59     }
60
61     /**
62      * LOAD SETTINGS
63      */
64     public void loadSettings() {
65         try {
66             Configuration config = this.bridge.getConfiguration();
67             username = config.get(CONFIG_EMAIL).toString();
68             password = config.get(CONFIG_PASS).toString();
69             cloudDiscoveryEnabled = Boolean.parseBoolean(config.get(CONFIG_DISCOVERY_CLOUD).toString());
70             udpDiscoveryEnabled = Boolean.parseBoolean(config.get(CONFIG_DISCOVERY_UDP).toString());
71             cloudReconnectIntervalM = Integer.valueOf(config.get(CONFIG_CLOUD_UPDATE_INTERVAL).toString());
72             discoveryIntervalM = Integer.valueOf(config.get(CONFIG_DISCOVERY_INTERVAL).toString());
73         } catch (Exception e) {
74             logger.warn("{} error reading configuration: '{}'", bridge.getUID(), e.getMessage());
75         }
76     }
77 }