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 class UniFiClientCache extends UniFiCache<UniFiClient> {
|
||||||
|
|
||||||
public UniFiClientCache() {
|
public UniFiClientCache() {
|
||||||
super(PREFIX_MAC, PREFIX_IP, PREFIX_HOSTNAME, PREFIX_ALIAS);
|
super(PREFIX_ID, PREFIX_MAC, PREFIX_IP, PREFIX_HOSTNAME, PREFIX_ALIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSuffix(UniFiClient client, String prefix) {
|
protected String getSuffix(UniFiClient client, String prefix) {
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
|
case PREFIX_ID:
|
||||||
|
return client.getId();
|
||||||
case PREFIX_MAC:
|
case PREFIX_MAC:
|
||||||
return client.getMac();
|
return client.getMac();
|
||||||
case PREFIX_IP:
|
case PREFIX_IP:
|
||||||
|
|||||||
@ -120,7 +120,7 @@ public abstract class UniFiClient {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format(
|
return String.format(
|
||||||
"UniFiClient{mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, blocked: %b, device: %s}",
|
"UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, blocked: %b, device: %s}",
|
||||||
mac, ip, hostname, alias, isWired(), blocked, getDevice());
|
id, mac, ip, hostname, alias, isWired(), blocked, getDevice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
package org.openhab.binding.unifi.internal.api.model;
|
package org.openhab.binding.unifi.internal.api.model;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@ -40,12 +42,15 @@ import com.google.gson.GsonBuilder;
|
|||||||
*
|
*
|
||||||
* @author Matthew Bowman - Initial contribution
|
* @author Matthew Bowman - Initial contribution
|
||||||
* @author Patrik Wimnell - Blocking / Unblocking client support
|
* @author Patrik Wimnell - Blocking / Unblocking client support
|
||||||
|
* @author Jacob Laursen - Fix online/blocked channels (broken by UniFi Controller 5.12.35)
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class UniFiController {
|
public class UniFiController {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(UniFiController.class);
|
private final Logger logger = LoggerFactory.getLogger(UniFiController.class);
|
||||||
|
|
||||||
|
private Map<String, String> cidToIdCache = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
private UniFiSiteCache sitesCache = new UniFiSiteCache();
|
private UniFiSiteCache sitesCache = new UniFiSiteCache();
|
||||||
|
|
||||||
private UniFiDeviceCache devicesCache = new UniFiDeviceCache();
|
private UniFiDeviceCache devicesCache = new UniFiDeviceCache();
|
||||||
@ -172,18 +177,22 @@ public class UniFiController {
|
|||||||
|
|
||||||
// Client API
|
// Client API
|
||||||
|
|
||||||
public @Nullable UniFiClient getClient(@Nullable String id) {
|
public @Nullable UniFiClient getClient(@Nullable String cid) {
|
||||||
UniFiClient client = null;
|
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) {
|
synchronized (this) {
|
||||||
// mgb: first check active clients and fallback to insights if not found
|
// 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) {
|
if (client == null) {
|
||||||
client = insightsCache.get(id);
|
client = insightsCache.get(id != null ? id : cid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (client == null) {
|
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;
|
return client;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user