2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.unifi.internal.api.dto;
15 import java.time.Instant;
17 import org.openhab.binding.unifi.internal.api.cache.UniFiControllerCache;
18 import org.openhab.binding.unifi.internal.api.util.UniFiTidyLowerCaseStringDeserializer;
19 import org.openhab.binding.unifi.internal.api.util.UniFiTimestampDeserializer;
21 import com.google.gson.annotations.JsonAdapter;
22 import com.google.gson.annotations.SerializedName;
25 * The {@link UniFiClient} is the base data model for any (wired or wireless) connected to a UniFi network.
27 * @author Matthew Bowman - Initial contribution
28 * @author Patrik Wimnell - Blocking / Unblocking client support
30 public abstract class UniFiClient implements HasId {
32 private final transient UniFiControllerCache cache;
34 @SerializedName("_id")
37 private String siteId;
39 @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
44 private String hostname;
48 private Integer uptime;
50 @JsonAdapter(UniFiTimestampDeserializer.class)
51 private Instant lastSeen;
53 private boolean blocked;
55 @SerializedName("is_guest")
56 private boolean guest;
58 @SerializedName("fixed_ip")
59 private String fixedIp;
61 @SerializedName("satisfaction")
62 private Integer experience;
64 protected UniFiClient(final UniFiControllerCache cache) {
69 public String getId() {
73 public String getMac() {
77 public String getIp() {
78 return this.ip == null || this.ip.isBlank() ? this.fixedIp : this.ip;
81 public String getHostname() {
85 public String getName() {
89 public Integer getUptime() {
93 public Instant getLastSeen() {
97 public boolean isBlocked() {
101 public abstract boolean isWired();
103 public final boolean isWireless() {
107 protected abstract String getDeviceMac();
109 public UniFiSite getSite() {
110 return cache.getSite(siteId);
113 public UniFiDevice getDevice() {
114 return cache.getDevice(getDeviceMac());
117 public boolean isGuest() {
121 public Integer getExperience() {
126 public String toString() {
127 return String.format(
128 "UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', name: '%s', wired: %b, guest: %b, blocked: %b, experience: %d, device: %s}",
129 id, mac, getIp(), hostname, name, isWired(), guest, blocked, experience, getDevice());