]> git.basschouten.com Git - openhab-addons.git/blob
9fc925195e23729ace71ff448465240652738c7d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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
17 import com.google.gson.annotations.SerializedName;
18
19 /**
20  * The {@link UniFiSite} represents the data model of a UniFi site.
21  *
22  * @author Matthew Bowman - Initial contribution
23  * @author Mark Herwege - Added guest vouchers
24  */
25 public class UniFiSite implements HasId {
26
27     private final transient UniFiControllerCache cache;
28
29     public UniFiSite(final UniFiControllerCache cache) {
30         this.cache = cache;
31     }
32
33     @SerializedName("_id")
34     private String id;
35
36     private String name;
37
38     private String desc;
39
40     @Override
41     public String getId() {
42         return id;
43     }
44
45     public String getName() {
46         return name;
47     }
48
49     public String getDescription() {
50         return desc;
51     }
52
53     public UniFiControllerCache getCache() {
54         return cache;
55     }
56
57     public String getVoucher() {
58         UniFiVoucher voucher = cache.getVoucher(this);
59         if (voucher == null) {
60             return null;
61         }
62         return voucher.getCode();
63     }
64
65     public boolean isSite(final UniFiSite site) {
66         return site != null && id.equals(site.getId());
67     }
68
69     public boolean matchesName(final String siteName) {
70         return siteName.equalsIgnoreCase(desc) || siteName.equalsIgnoreCase(name) || siteName.equalsIgnoreCase(id);
71     }
72
73     @Override
74     public String toString() {
75         return String.format("UniFiSite{id: '%s', name: '%s', desc: '%s'}", id, name, desc);
76     }
77 }