2 * Copyright (c) 2010-2024 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.network.internal;
15 import java.math.BigDecimal;
16 import java.util.ArrayList;
17 import java.util.List;
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;
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.
27 * @author David Graeff - Initial contribution
30 public class NetworkBindingConfiguration {
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;
40 private List<NetworkBindingConfigurationListener> listeners = new ArrayList<>();
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;
49 NetworkUtils networkUtils = new NetworkUtils();
50 this.arpPingUtilMethod = networkUtils.determineNativeARPpingMethod(arpPingToolPath);
55 public void addNetworkBindingConfigurationListener(NetworkBindingConfigurationListener listener) {
56 listeners.add(listener);
59 private void notifyListeners() {
60 listeners.forEach(NetworkBindingConfigurationListener::bindingConfigurationChanged);
64 public String toString() {
65 return "NetworkBindingConfiguration{" + "allowSystemPings=" + allowSystemPings + ", allowDHCPlisten="
66 + allowDHCPlisten + ", cacheDeviceStateTimeInMS=" + cacheDeviceStateTimeInMS + ", arpPingToolPath='"
67 + arpPingToolPath + '\'' + ", arpPingUtilMethod=" + arpPingUtilMethod + ", preferResponseTimeAsLatency="
68 + preferResponseTimeAsLatency + '}';