]> git.basschouten.com Git - openhab-addons.git/blob
1ad6420ccce40dc0fcd504060375eeaeea969991
[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 type;
42
43     private String name;
44
45     private String siteId;
46
47     private UniFiPortTable[] portTable;
48
49     private JsonObject[] portOverrides;
50
51     private boolean disabled;
52
53     public UniFiDevice(final UniFiControllerCache cache) {
54         this.cache = cache;
55     }
56
57     @Override
58     public String getId() {
59         return id;
60     }
61
62     public String getType() {
63         return type;
64     }
65
66     public String getModel() {
67         return model;
68     }
69
70     public String getName() {
71         return name == null || name.isBlank() ? mac : name;
72     }
73
74     public String getMac() {
75         return mac;
76     }
77
78     public UniFiSite getSite() {
79         return cache.getSite(siteId);
80     }
81
82     public UniFiPortTable[] getPortTable() {
83         return portTable;
84     }
85
86     public JsonObject[] getPortOverrides() {
87         return portOverrides;
88     }
89
90     public boolean isDisabled() {
91         return disabled;
92     }
93
94     @Override
95     public String toString() {
96         return String.format("UniFiDevice{mac: '%s', name: '%s', type: %s, model: '%s', disabled: %b, site: %s}", mac,
97                 name, type, model, disabled, getSite());
98     }
99 }