mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Fix online/blocked channels. (#11451)
Fixes #7001 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
4d5fd84c49
commit
7ec833df18
@ -26,12 +26,14 @@ import org.openhab.binding.unifi.internal.api.model.UniFiClient;
|
||||
public class UniFiClientCache extends UniFiCache<UniFiClient> {
|
||||
|
||||
public UniFiClientCache() {
|
||||
super(PREFIX_MAC, PREFIX_IP, PREFIX_HOSTNAME, PREFIX_ALIAS);
|
||||
super(PREFIX_ID, PREFIX_MAC, PREFIX_IP, PREFIX_HOSTNAME, PREFIX_ALIAS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSuffix(UniFiClient client, String prefix) {
|
||||
switch (prefix) {
|
||||
case PREFIX_ID:
|
||||
return client.getId();
|
||||
case PREFIX_MAC:
|
||||
return client.getMac();
|
||||
case PREFIX_IP:
|
||||
|
@ -120,7 +120,7 @@ public abstract class UniFiClient {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"UniFiClient{mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, blocked: %b, device: %s}",
|
||||
mac, ip, hostname, alias, isWired(), blocked, getDevice());
|
||||
"UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, blocked: %b, device: %s}",
|
||||
id, mac, ip, hostname, alias, isWired(), blocked, getDevice());
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
package org.openhab.binding.unifi.internal.api.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -40,12 +42,15 @@ import com.google.gson.GsonBuilder;
|
||||
*
|
||||
* @author Matthew Bowman - Initial contribution
|
||||
* @author Patrik Wimnell - Blocking / Unblocking client support
|
||||
* @author Jacob Laursen - Fix online/blocked channels (broken by UniFi Controller 5.12.35)
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class UniFiController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(UniFiController.class);
|
||||
|
||||
private Map<String, String> cidToIdCache = new ConcurrentHashMap<String, String>();
|
||||
|
||||
private UniFiSiteCache sitesCache = new UniFiSiteCache();
|
||||
|
||||
private UniFiDeviceCache devicesCache = new UniFiDeviceCache();
|
||||
@ -172,18 +177,22 @@ public class UniFiController {
|
||||
|
||||
// Client API
|
||||
|
||||
public @Nullable UniFiClient getClient(@Nullable String id) {
|
||||
public @Nullable UniFiClient getClient(@Nullable String cid) {
|
||||
UniFiClient client = null;
|
||||
if (id != null && !id.isBlank()) {
|
||||
if (cid != null && !cid.isBlank()) {
|
||||
// Prefer lookups through _id, until initialized use cid.
|
||||
String id = cidToIdCache.get(cid);
|
||||
synchronized (this) {
|
||||
// mgb: first check active clients and fallback to insights if not found
|
||||
client = clientsCache.get(id);
|
||||
client = clientsCache.get(id != null ? id : cid);
|
||||
if (client == null) {
|
||||
client = insightsCache.get(id);
|
||||
client = insightsCache.get(id != null ? id : cid);
|
||||
}
|
||||
}
|
||||
if (client == null) {
|
||||
logger.debug("Could not find a matching client for id = {}", id);
|
||||
logger.debug("Could not find a matching client for cid = {}", cid);
|
||||
} else {
|
||||
cidToIdCache.put(cid, client.id);
|
||||
}
|
||||
}
|
||||
return client;
|
||||
|
Loading…
Reference in New Issue
Block a user