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 @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
45 private String hostname;
47 @SerializedName("name")
48 @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
51 private Integer uptime;
53 @JsonAdapter(UniFiTimestampDeserializer.class)
54 private Instant lastSeen;
56 private boolean blocked;
58 @SerializedName("is_guest")
59 private boolean guest;
61 @SerializedName("fixed_ip")
62 private String fixedIp;
64 @SerializedName("satisfaction")
65 private Integer experience;
67 protected UniFiClient(final UniFiControllerCache cache) {
72 public String getId() {
76 public String getMac() {
80 public String getIp() {
81 return this.ip == null || this.ip.isBlank() ? this.fixedIp : this.ip;
84 public String getHostname() {
88 public String getAlias() {
92 public Integer getUptime() {
96 public Instant getLastSeen() {
100 public boolean isBlocked() {
104 public abstract boolean isWired();
106 public final boolean isWireless() {
110 protected abstract String getDeviceMac();
112 public UniFiSite getSite() {
113 return cache.getSite(siteId);
116 public UniFiDevice getDevice() {
117 return cache.getDevice(getDeviceMac());
120 public boolean isGuest() {
124 public Integer getExperience() {
129 public String toString() {
130 return String.format(
131 "UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, guest: %b, blocked: %b, experience: %d, device: %s}",
132 id, mac, getIp(), hostname, alias, isWired(), guest, blocked, experience, getDevice());