]> git.basschouten.com Git - openhab-addons.git/blob
8449fd515c0b32b63064a20ac3e77f11dcd18780
[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.unifi.internal.api.dto;
14
15 import org.openhab.binding.unifi.internal.api.cache.UniFiControllerCache;
16 import org.openhab.binding.unifi.internal.api.util.UniFiTidyLowerCaseStringDeserializer;
17
18 import com.google.gson.JsonObject;
19 import com.google.gson.annotations.JsonAdapter;
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * The {@link UniFiDevice} represents the data model of a UniFi Wireless Device
24  * (better known as an Access Point).
25  *
26  * @author Matthew Bowman - Initial contribution
27  * @author Hilbrand Bouwkamp - Added PoEPort support
28  */
29 public class UniFiDevice implements HasId {
30
31     protected final transient UniFiControllerCache cache;
32
33     @SerializedName("_id")
34     private String id;
35
36     @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
37     private String mac;
38
39     private String model;
40
41     private String version;
42
43     private String serial;
44
45     private String type;
46
47     private String name;
48
49     private String siteId;
50
51     private UniFiPortTable[] portTable;
52
53     private JsonObject[] portOverrides;
54
55     private boolean disabled;
56
57     public UniFiDevice(final UniFiControllerCache cache) {
58         this.cache = cache;
59     }
60
61     @Override
62     public String getId() {
63         return id;
64     }
65
66     public String getType() {
67         return type;
68     }
69
70     public String getModel() {
71         return model;
72     }
73
74     public String getVersion() {
75         return version;
76     }
77
78     public String getSerial() {
79         return serial;
80     }
81
82     public String getName() {
83         return name == null || name.isBlank() ? mac : name;
84     }
85
86     public String getMac() {
87         return mac;
88     }
89
90     public UniFiSite getSite() {
91         return cache.getSite(siteId);
92     }
93
94     public UniFiPortTable[] getPortTable() {
95         return portTable;
96     }
97
98     public JsonObject[] getPortOverrides() {
99         return portOverrides;
100     }
101
102     public boolean isDisabled() {
103         return disabled;
104     }
105
106     @Override
107     public String toString() {
108         return String.format("UniFiDevice{mac: '%s', name: '%s', type: %s, model: '%s', disabled: %b, site: %s}", mac,
109                 name, type, model, disabled, getSite());
110     }
111 }