]> git.basschouten.com Git - openhab-addons.git/blob
9b68f09444b225c91edab2b279d0393ae327afc6
[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 TapoDeviceConfiguration} class contains fields mapping bridge configuration parameters.
23  *
24  * @author Christian Wild - Initial contribution
25  */
26
27 @NonNullByDefault
28 public final class TapoDeviceConfiguration {
29     private final Logger logger = LoggerFactory.getLogger(TapoDeviceConfiguration.class);
30
31     /* THING CONFIGUTATION PROPERTYS */
32     public static final String CONFIG_DEVICE_IP = "ipAddress";
33     public static final String CONFIG_UPDATE_INTERVAL = "pollingInterval";
34
35     /* thing configuration parameter. */
36     public String ipAddress = "";
37     public Integer pollingInterval = 30;
38
39     private final Thing device;
40
41     /**
42      * Create settings
43      * 
44      * @param thing BridgeThing
45      */
46     public TapoDeviceConfiguration(Thing thing) {
47         this.device = thing;
48         loadSettings();
49     }
50
51     /**
52      * LOAD SETTINGS
53      */
54     public void loadSettings() {
55         try {
56             Configuration config = this.device.getConfiguration();
57             this.ipAddress = config.get(CONFIG_DEVICE_IP).toString();
58             this.pollingInterval = Integer.valueOf(config.get(CONFIG_UPDATE_INTERVAL).toString());
59         } catch (Exception e) {
60             logger.warn("{} error reading device-configuration: '{}'", device.getUID().toString(), e.getMessage());
61         }
62     }
63 }