2 * Copyright (c) 2010-2023 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;
23 import org.eclipse.jdt.annotation.Nullable;
26 * The {@link ShellyBindingConfiguration} class contains fields mapping binding configuration parameters.
28 * @author Markus Michels - Initial contribution
31 public class ShellyBindingConfiguration {
32 // Binding Configuration Properties
33 public static final String CONFIG_DEF_HTTP_USER = "defaultUserId";
34 public static final String CONFIG_DEF_HTTP_PWD = "defaultPassword";
35 public static final String CONFIG_LOCAL_IP = "localIP";
36 public static final String CONFIG_AUTOCOIOT = "autoCoIoT";
38 public String defaultUserId = "admin"; // default for http basic user id
39 public String defaultPassword = "admin"; // default for http basic auth password
40 public String localIP = ""; // default:use OH network config
41 public int httpPort = -1;
42 public boolean autoCoIoT = true;
44 public void updateFromProperties(Map<String, Object> properties) {
45 for (Map.Entry<String, Object> e : properties.entrySet()) {
47 case CONFIG_DEF_HTTP_USER:
48 defaultUserId = (String) e.getValue();
50 case CONFIG_DEF_HTTP_PWD:
51 defaultPassword = (String) e.getValue();
54 localIP = (String) e.getValue();
56 case CONFIG_AUTOCOIOT:
57 Object value = e.getValue();
58 if (value instanceof String stringValue) {
59 // support config through shelly.cfg
60 autoCoIoT = "true".equalsIgnoreCase(stringValue);
62 autoCoIoT = (boolean) value;
70 public void updateFromProperties(@Nullable Dictionary<String, Object> properties) {
71 if (properties == null) { // saw this once
74 List<String> keys = Collections.list(properties.keys());
75 Map<String, Object> dictCopy = keys.stream().collect(Collectors.toMap(Function.identity(), properties::get));
76 updateFromProperties(dictCopy);