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.asuswrt.internal.structures;
15 import static org.openhab.binding.asuswrt.internal.constants.AsuswrtBindingConstants.*;
16 import static org.openhab.binding.asuswrt.internal.constants.AsuswrtBindingSettings.*;
17 import static org.openhab.binding.asuswrt.internal.helpers.AsuswrtUtils.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import com.google.gson.JsonObject;
26 * The {@link AsuswrtIpInfo} class stores IP data.
28 * @author Christian Wild - Initial contribution
31 public class AsuswrtIpInfo {
32 private final Logger logger = LoggerFactory.getLogger(AsuswrtIpInfo.class);
33 private AsuswrtTraffic traffic = new AsuswrtTraffic();
34 private String ifName = "";
35 private String hwAddress = "";
36 private String ipAddress = "";
37 private String ipProto = "";
38 private String subnet = "";
39 private String gateway = "";
40 private String dnsServer = "";
41 private Boolean connected = false;
43 public AsuswrtIpInfo() {
49 * @param interfaceName name of interface
50 * @param jsonObject with ipInfo
52 public AsuswrtIpInfo(String ifName, JsonObject jsonObject) {
54 traffic = new AsuswrtTraffic(ifName);
62 public void setData(JsonObject jsonObject) {
63 if (ifName.startsWith(INTERFACE_LAN)) {
64 logger.trace("(AsuswrtIpInfo) setData for interface {}", INTERFACE_LAN);
65 hwAddress = jsonObjectToString(jsonObject, JSON_MEMBER_MAC, hwAddress);
66 ipAddress = jsonObjectToString(jsonObject, JSON_MEMBER_LAN_IP, ipAddress);
67 subnet = jsonObjectToString(jsonObject, JSON_MEMBER_LAN_NETMASK, subnet);
68 gateway = jsonObjectToString(jsonObject, JSON_MEMBER_LAN_GATEWAY, gateway);
69 ipProto = jsonObjectToString(jsonObject, JSON_MEMBER_LAN_PROTO, ipProto);
70 } else if (ifName.startsWith(INTERFACE_WAN)) {
71 logger.trace("(AsuswrtIpInfo) setData for interface {}", INTERFACE_WAN);
72 hwAddress = jsonObjectToString(jsonObject, JSON_MEMBER_MAC, hwAddress);
73 ipAddress = jsonObjectToString(jsonObject, JSON_MEMBER_WAN_IP, ipAddress);
74 subnet = jsonObjectToString(jsonObject, JSON_MEMBER_WAN_NETMASK, subnet);
75 gateway = jsonObjectToString(jsonObject, JSON_MEMBER_WAN_GATEWAY, gateway);
76 ipProto = jsonObjectToString(jsonObject, JSON_MEMBER_WAN_PROTO, ipProto);
77 dnsServer = jsonObjectToString(jsonObject, JSON_MEMBER_WAN_DNS_SERVER, dnsServer);
78 connected = (jsonObjectToInt(jsonObject, JSON_MEMBER_WAN_CONNECTED) == 1);
80 if (jsonObject.has(JSON_MEMBER_TRAFFIC)) {
81 traffic.setData(jsonObject.getAsJsonObject(JSON_MEMBER_TRAFFIC));
89 public AsuswrtTraffic getTraffic() {
93 public String getMAC() {
97 public String getIpAddress() {
101 public String getSubnet() {
105 public String getGateway() {
109 public String getIpProto() {
113 public String getDNSNServer() {
117 public String getName() {
121 public Boolean isConnected() {