2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.shelly.internal.config;
15 import java.util.Collections;
16 import java.util.Dictionary;
17 import java.util.List;
19 import java.util.function.Function;
20 import java.util.stream.Collectors;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
25 * The {@link ShellyBindingConfiguration} class contains fields mapping binding configuration parameters.
27 * @author Markus Michels - Initial contribution
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_AUTOCOIOT = "autoCoIoT";
36 public String defaultUserId = ""; // default for http basic user id
37 public String defaultPassword = ""; // default for http basic auth password
38 public boolean autoCoIoT = true;
40 public void updateFromProperties(Map<String, Object> properties) {
41 for (Map.Entry<String, Object> e : properties.entrySet()) {
42 if (e.getValue() == null) {
46 case CONFIG_DEF_HTTP_USER:
47 defaultUserId = (String) e.getValue();
49 case CONFIG_DEF_HTTP_PWD:
50 defaultPassword = (String) e.getValue();
52 case CONFIG_AUTOCOIOT:
53 autoCoIoT = (boolean) e.getValue();
60 public void updateFromProperties(Dictionary<String, Object> properties) {
61 List<String> keys = Collections.list(properties.keys());
62 Map<String, Object> dictCopy = keys.stream().collect(Collectors.toMap(Function.identity(), properties::get));
63 updateFromProperties(dictCopy);