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