]> git.basschouten.com Git - openhab-addons.git/blob
1d53b441e6095844d8187dffc4c98f09bd016cd1
[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.shelly.internal.config;
14
15 import java.util.Collections;
16 import java.util.Dictionary;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.function.Function;
20 import java.util.stream.Collectors;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23
24 /**
25  * The {@link ShellyBindingConfiguration} class contains fields mapping binding configuration parameters.
26  *
27  * @author Markus Michels - Initial contribution
28  */
29 @NonNullByDefault
30 public class ShellyBindingConfiguration {
31     // Binding Configuration Properties
32     public static final String CONFIG_DEF_HTTP_USER = "defaultUserId";
33     public static final String CONFIG_DEF_HTTP_PWD = "defaultPassword";
34     public static final String CONFIG_LOCAL_IP = "localIP";
35     public static final String CONFIG_AUTOCOIOT = "autoCoIoT";
36
37     public String defaultUserId = ""; // default for http basic user id
38     public String defaultPassword = ""; // default for http basic auth password
39     public String localIP = ""; // default:use OH network config
40     public boolean autoCoIoT = true;
41
42     public void updateFromProperties(Map<String, Object> properties) {
43         for (Map.Entry<String, Object> e : properties.entrySet()) {
44             switch (e.getKey()) {
45                 case CONFIG_DEF_HTTP_USER:
46                     defaultUserId = (String) e.getValue();
47                     break;
48                 case CONFIG_DEF_HTTP_PWD:
49                     defaultPassword = (String) e.getValue();
50                     break;
51                 case CONFIG_LOCAL_IP:
52                     localIP = (String) e.getValue();
53                     break;
54                 case CONFIG_AUTOCOIOT:
55                     autoCoIoT = (boolean) e.getValue();
56                     break;
57             }
58
59         }
60     }
61
62     public void updateFromProperties(Dictionary<String, Object> properties) {
63         List<String> keys = Collections.list(properties.keys());
64         Map<String, Object> dictCopy = keys.stream().collect(Collectors.toMap(Function.identity(), properties::get));
65         updateFromProperties(dictCopy);
66     }
67 }