]> git.basschouten.com Git - openhab-addons.git/blob
a1b92cc3bf5f425a07d65ac008d9751b87de6c34
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.network.internal;
14
15 import java.math.BigDecimal;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.network.internal.utils.NetworkUtils;
21 import org.openhab.binding.network.internal.utils.NetworkUtils.ArpPingUtilEnum;
22
23 /**
24  * Contains the binding configuration and default values. The field names represent the configuration names,
25  * do not rename them if you don't intend to break the configuration interface.
26  *
27  * @author David Graeff - Initial contribution
28  */
29 @NonNullByDefault
30 public class NetworkBindingConfiguration {
31
32     public boolean allowSystemPings = true;
33     public boolean allowDHCPlisten = true;
34     public BigDecimal cacheDeviceStateTimeInMS = BigDecimal.valueOf(2000);
35     public String arpPingToolPath = "arping";
36     public ArpPingUtilEnum arpPingUtilMethod = ArpPingUtilEnum.DISABLED;
37     // For backwards compatibility reasons, the default is to use the ping method execution time as latency value
38     public boolean preferResponseTimeAsLatency = false;
39
40     private List<NetworkBindingConfigurationListener> listeners = new ArrayList<>();
41
42     public void update(NetworkBindingConfiguration newConfiguration) {
43         this.allowSystemPings = newConfiguration.allowSystemPings;
44         this.allowDHCPlisten = newConfiguration.allowDHCPlisten;
45         this.cacheDeviceStateTimeInMS = newConfiguration.cacheDeviceStateTimeInMS;
46         this.arpPingToolPath = newConfiguration.arpPingToolPath;
47         this.preferResponseTimeAsLatency = newConfiguration.preferResponseTimeAsLatency;
48
49         NetworkUtils networkUtils = new NetworkUtils();
50         this.arpPingUtilMethod = networkUtils.determineNativeARPpingMethod(arpPingToolPath);
51
52         notifyListeners();
53     }
54
55     public void addNetworkBindingConfigurationListener(NetworkBindingConfigurationListener listener) {
56         listeners.add(listener);
57     }
58
59     private void notifyListeners() {
60         listeners.forEach(NetworkBindingConfigurationListener::bindingConfigurationChanged);
61     }
62
63     @Override
64     public String toString() {
65         return "NetworkBindingConfiguration{" + "allowSystemPings=" + allowSystemPings + ", allowDHCPlisten="
66                 + allowDHCPlisten + ", cacheDeviceStateTimeInMS=" + cacheDeviceStateTimeInMS + ", arpPingToolPath='"
67                 + arpPingToolPath + '\'' + ", arpPingUtilMethod=" + arpPingUtilMethod + ", preferResponseTimeAsLatency="
68                 + preferResponseTimeAsLatency + '}';
69     }
70 }