]> git.basschouten.com Git - openhab-addons.git/blob
daed14182c2e5a3ed3b5f46110233a1352983dac
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.model;
14
15 import org.apache.commons.lang.StringUtils;
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  */
27 public class UniFiDevice {
28
29     protected final transient UniFiController controller;
30
31     @SerializedName("_id")
32     private String id;
33
34     @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
35     private String mac;
36
37     private String model;
38
39     private String name;
40
41     private String siteId;
42
43     public UniFiDevice(UniFiController controller) {
44         this.controller = controller;
45     }
46
47     public String getId() {
48         return id;
49     }
50
51     public String getModel() {
52         return model;
53     }
54
55     public String getName() {
56         return StringUtils.defaultIfBlank(name, mac);
57     }
58
59     public String getMac() {
60         return mac;
61     }
62
63     public UniFiSite getSite() {
64         return controller.getSite(siteId);
65     }
66
67     @Override
68     public String toString() {
69         return String.format("UniFiDevice{mac: '%s', name: '%s', model: '%s', site: %s}", mac, name, model, getSite());
70     }
71 }