]> git.basschouten.com Git - openhab-addons.git/blob
0cd1e1b38a00e971ee1f5c49fed902b25cd60c56
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.annotations.JsonAdapter;
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * The {@link UniFiDevice} represents the data model of a UniFi Wireless Device
23  * (better known as an Access Point).
24  *
25  * @author Matthew Bowman - Initial contribution
26  * @author Hilbrand Bouwkamp - Added PoEPort support
27  */
28 public class UniFiDevice implements HasId {
29
30     protected final transient UniFiControllerCache cache;
31
32     @SerializedName("_id")
33     private String id;
34
35     @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
36     private String mac;
37
38     private String model;
39
40     private String name;
41
42     private String siteId;
43
44     private UniFiPortTable[] portTable;
45
46     public UniFiDevice(final UniFiControllerCache cache) {
47         this.cache = cache;
48     }
49
50     @Override
51     public String getId() {
52         return id;
53     }
54
55     public String getModel() {
56         return model;
57     }
58
59     public String getName() {
60         return name == null || name.isBlank() ? mac : name;
61     }
62
63     public String getMac() {
64         return mac;
65     }
66
67     public UniFiSite getSite() {
68         return cache.getSite(siteId);
69     }
70
71     public UniFiPortTable[] getPortTable() {
72         return portTable;
73     }
74
75     @Override
76     public String toString() {
77         return String.format("UniFiDevice{mac: '%s', name: '%s', model: '%s', site: %s}", mac, name, model, getSite());
78     }
79 }