[unifi] Added channels name and hostname to client things. (#14283)

* [unifi] Added channels name and hostname to client things.

Also some changes related to the guestVoucher changes.

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
Hilbrand Bouwkamp 2023-01-30 08:59:19 +01:00 committed by GitHub
parent 15a25db130
commit bf105008a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 88 additions and 23 deletions

View File

@ -168,6 +168,8 @@ The `wirelessClient` information that is retrieved is available as these channel
| Channel ID | Item Type | Description | Permissions |
|------------|----------------------|----------------------------------------------------------------------|-------------|
| online | Switch | Online status of the client | Read |
| name | String | Name of device (from the controller web UI) | Read |
| hostname | String | Hostname of device (from the controller web UI) | Read |
| site | String | Site name (from the controller web UI) the client is associated with | Read |
| macAddress | String | MAC address of the client | Read |
| ipAddress | String | IP address of the client | Read |
@ -192,6 +194,8 @@ The `wiredClient` information that is retrieved is available as these channels:
| Channel ID | Item Type | Description | Permissions |
|------------|----------------------|----------------------------------------------------------------------|-------------|
| online | Switch | Online status of the client | Read |
| name | String | Name of device (from the controller web UI) | Read |
| hostname | String | Hostname of device (from the controller web UI) | Read |
| site | String | Site name (from the controller web UI) the client is associated with | Read |
| macAddress | String | MAC address of the client | Read |
| ipAddress | String | IP address of the client | Read |

View File

@ -61,6 +61,8 @@ public final class UniFiBindingConstants {
// List of common wired + wireless client channels
public static final String CHANNEL_ONLINE = "online";
public static final String CHANNEL_NAME = "name";
public static final String CHANNEL_HOSTNAME = "hostname";
public static final String CHANNEL_SITE = "site";
public static final String CHANNEL_MAC_ADDRESS = "macAddress";
public static final String CHANNEL_IP_ADDRESS = "ipAddress";

View File

@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
abstract class UniFiCache<T extends @Nullable HasId> {
public enum Prefix {
ALIAS,
DESC,
HOSTNAME,
ID,

View File

@ -12,11 +12,11 @@
*/
package org.openhab.binding.unifi.internal.api.cache;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.ALIAS;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.HOSTNAME;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.ID;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.IP;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.MAC;
import static org.openhab.binding.unifi.internal.api.cache.UniFiCache.Prefix.NAME;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -27,7 +27,7 @@ import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
* {@link UniFiClient} instances.
*
* The cache uses the following prefixes: <code>mac</code>, <code>ip</code>, <code>hostname</code>, and
* <code>alias</code>
* <code>name</code>
*
* @author Matthew Bowman - Initial contribution
*/
@ -35,7 +35,7 @@ import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
class UniFiClientCache extends UniFiCache<UniFiClient> {
public UniFiClientCache() {
super(ID, MAC, IP, HOSTNAME, ALIAS);
super(ID, MAC, IP, HOSTNAME, NAME);
}
@Override
@ -48,11 +48,15 @@ class UniFiClientCache extends UniFiCache<UniFiClient> {
case IP:
return client.getIp();
case HOSTNAME:
return client.getHostname();
case ALIAS:
return client.getAlias();
return safeTidy(client.getHostname());
case NAME:
return safeTidy(client.getName());
default:
return null;
}
}
private static @Nullable String safeTidy(final @Nullable String value) {
return value == null ? null : value.trim().toLowerCase();
}
}

View File

@ -41,12 +41,9 @@ public abstract class UniFiClient implements HasId {
private String ip;
@JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
private String hostname;
@SerializedName("name")
@JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
private String alias;
private String name;
private Integer uptime;
@ -85,8 +82,8 @@ public abstract class UniFiClient implements HasId {
return hostname;
}
public String getAlias() {
return alias;
public String getName() {
return name;
}
public Integer getUptime() {
@ -128,7 +125,7 @@ public abstract class UniFiClient implements HasId {
@Override
public String toString() {
return String.format(
"UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', alias: '%s', wired: %b, guest: %b, blocked: %b, experience: %d, device: %s}",
id, mac, getIp(), hostname, alias, isWired(), guest, blocked, experience, getDevice());
"UniFiClient{id: '%s', mac: '%s', ip: '%s', hostname: '%s', name: '%s', wired: %b, guest: %b, blocked: %b, experience: %d, device: %s}",
id, mac, getIp(), hostname, name, isWired(), guest, blocked, experience, getDevice());
}
}

View File

@ -19,9 +19,11 @@ import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_C
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_ESSID;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_EXPERIENCE;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_GUEST;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_HOSTNAME;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_IP_ADDRESS;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_LAST_SEEN;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_MAC_ADDRESS;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_NAME;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_ONLINE;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_RECONNECT;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_RSSI;
@ -176,6 +178,19 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler<UniFiClient,
state = OnOffType.from(clientHome);
break;
// :name
case CHANNEL_NAME:
if (client.getName() != null) {
state = StringType.valueOf(client.getName());
}
break;
// :hostname
case CHANNEL_HOSTNAME:
if (client.getHostname() != null) {
state = StringType.valueOf(client.getHostname());
}
break;
// :site
case CHANNEL_SITE:
if (site != null && site.getDescription() != null && !site.getDescription().isBlank()) {

View File

@ -12,7 +12,12 @@
*/
package org.openhab.binding.unifi.internal.handler;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.*;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_GUEST_CLIENTS;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_GUEST_VOUCHER;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_GUEST_VOUCHERS_GENERATE;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_TOTAL_CLIENTS;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_WIRED_CLIENTS;
import static org.openhab.binding.unifi.internal.UniFiBindingConstants.CHANNEL_WIRELESS_CLIENTS;
import java.util.function.Predicate;
@ -88,7 +93,7 @@ public class UniFiSiteThingHandler extends UniFiBaseThingHandler<UniFiSite, UniF
state = countClients(site, c -> c.isGuest());
break;
case CHANNEL_GUEST_VOUCHER:
String voucher = site.getVoucher();
final String voucher = site.getVoucher();
state = (voucher != null) ? StringType.valueOf(voucher) : UnDefType.UNDEF;
break;
case CHANNEL_GUEST_VOUCHERS_GENERATE:
@ -111,11 +116,11 @@ public class UniFiSiteThingHandler extends UniFiBaseThingHandler<UniFiSite, UniF
final String channelID = channelUID.getId();
if (CHANNEL_GUEST_VOUCHERS_GENERATE.equals(channelID)) {
Channel channel = getThing().getChannel(CHANNEL_GUEST_VOUCHERS_GENERATE);
final Channel channel = getThing().getChannel(CHANNEL_GUEST_VOUCHERS_GENERATE);
if (channel == null) {
return false;
}
UniFiVoucherChannelConfig config = channel.getConfiguration().as(UniFiVoucherChannelConfig.class);
final UniFiVoucherChannelConfig config = channel.getConfiguration().as(UniFiVoucherChannelConfig.class);
final int count = config.getCount();
final int expire = config.getExpiration();
final int users = config.getVoucherUsers();

View File

@ -147,7 +147,7 @@ public class UniFiThingDiscoveryService extends AbstractDiscoveryService
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withBridge(bridgeUID)
.withRepresentationProperty(PARAMETER_CID).withTTL(TTL_SECONDS).withProperties(properties)
.withLabel(uc.getAlias()).build());
.withLabel(uc.getName()).build());
}
}

View File

@ -54,7 +54,7 @@
<config-description uri="thing-type:unifi:client">
<parameter name="cid" type="text" required="true">
<label>Client ID</label>
<description>The MAC address, IP address, hostname or alias of the client</description>
<description>The MAC address, IP address, hostname or name of the client</description>
</parameter>
<parameter name="site" type="text" required="false">
<label>Site</label>

View File

@ -21,7 +21,7 @@ thing-type.unifi.wlan.description = A UniFi Wireless LAN
# thing types config
thing-type.config.unifi.client.cid.label = Client ID
thing-type.config.unifi.client.cid.description = The MAC address, IP address, hostname or alias of the client
thing-type.config.unifi.client.cid.description = The MAC address, IP address, hostname or name of the client
thing-type.config.unifi.client.considerHome.label = Consider Home Interval
thing-type.config.unifi.client.considerHome.description = The interval in seconds to consider the client as home
thing-type.config.unifi.client.site.label = Site
@ -61,12 +61,21 @@ channel-type.unifi.guest.label = Guest
channel-type.unifi.guest.description = Is the client connected a guest
channel-type.unifi.guestClients.label = Guest Clients
channel-type.unifi.guestClients.description = Number of guest clients connected
channel-type.unifi.guestVoucher.label = Guest Voucher
channel-type.unifi.guestVoucher.description = Guest voucher for access through the guest portal
channel-type.unifi.guestVouchersGenerate.label = Generate Guest Vouchers
channel-type.unifi.guestVouchersGenerate.description = Generate additional guest vouchers for access through the guest portal
channel-type.unifi.guestVouchersGenerate.command.option.GENERATE = Generate
channel-type.unifi.hostname.label = Hostname
channel-type.unifi.hostname.description = Hostname of the client
channel-type.unifi.ipAddress.label = IP Address
channel-type.unifi.ipAddress.description = IP address of the client
channel-type.unifi.lastSeen.label = Last Seen
channel-type.unifi.lastSeen.description = Timestamp of when the client was last seen
channel-type.unifi.macAddress.label = MAC Address
channel-type.unifi.macAddress.description = MAC address of the client
channel-type.unifi.name.label = Name
channel-type.unifi.name.description = Name of the client
channel-type.unifi.online.label = Online
channel-type.unifi.online.description = Online status of the client
channel-type.unifi.passphrase.label = Passphrase
@ -124,6 +133,18 @@ channel-type.unifi.wpaMode.description = WPA Mode of the Wi-Fi network
# channel types config
channel-type.config.unifi.guestVouchersGenerate.voucherCount.label = Number
channel-type.config.unifi.guestVouchersGenerate.voucherCount.description = Number of vouchers to create
channel-type.config.unifi.guestVouchersGenerate.voucherDataQuota.label = Data Transfer Quota
channel-type.config.unifi.guestVouchersGenerate.voucherDataQuota.description = Data transfer quota in MB per user, no limit if not set
channel-type.config.unifi.guestVouchersGenerate.voucherDownLimit.label = Download Speed Limit
channel-type.config.unifi.guestVouchersGenerate.voucherDownLimit.description = Download speed limit in kbps, no limit if not set
channel-type.config.unifi.guestVouchersGenerate.voucherExpiration.label = Expiration Time
channel-type.config.unifi.guestVouchersGenerate.voucherExpiration.description = Minutes a voucher is valid after activation
channel-type.config.unifi.guestVouchersGenerate.voucherUpLimit.label = Upload Speed Limit
channel-type.config.unifi.guestVouchersGenerate.voucherUpLimit.description = Upload speed limit in kbps, no limit if not set
channel-type.config.unifi.guestVouchersGenerate.voucherUsers.label = Users
channel-type.config.unifi.guestVouchersGenerate.voucherUsers.description = Number of users for voucher, 0 if no limit
channel-type.config.unifi.poeEnable.mode.label = On Mode
channel-type.config.unifi.poeEnable.mode.description = The value to set when setting PoE on.
channel-type.config.unifi.poeEnable.mode.option.auto = Auto
@ -137,7 +158,7 @@ error.bridge.offline.invalid_credentials = Invalid username and/or password - pl
error.bridge.offline.invalid_hostname = Invalid hostname - please double-check your configuration: {0}
error.bridge.offline.ssl_error = Error establishing an SSL connection with the UniFi controller: {0}
error.controller.parse_error = Could not parse JSON from the UniFi Controller. Is the bridge configured with the correct host and/or port?
error.thing.client.offline.configuration_error = You must define a MAC address, IP address, hostname or alias for this thing.
error.thing.client.offline.configuration_error = You must define a MAC address, IP address, hostname or name for this thing.
error.thing.offline.bridge_offline = The UniFi Controller is currently offline.
error.thing.offline.configuration_error = You must choose a UniFi Controller for this thing.
error.thing.poe.offline.configuration_error = The configuration parameter macAddress must be set and not be empty.

View File

@ -71,6 +71,8 @@
<channels>
<!-- common wired + wireless client channels -->
<channel id="online" typeId="online"/>
<channel id="name" typeId="name"/>
<channel id="hostname" typeId="hostname"/>
<channel id="site" typeId="site"/>
<channel id="macAddress" typeId="macAddress"/>
<channel id="ipAddress" typeId="ipAddress"/>
@ -95,6 +97,8 @@
<channels>
<!-- common wired + wireless client channels -->
<channel id="online" typeId="online"/>
<channel id="name" typeId="name"/>
<channel id="hostname" typeId="hostname"/>
<channel id="site" typeId="site"/>
<channel id="macAddress" typeId="macAddress"/>
<channel id="ipAddress" typeId="ipAddress"/>
@ -248,6 +252,20 @@
<state readOnly="true"></state>
</channel-type>
<channel-type id="name">
<item-type>String</item-type>
<label>Name</label>
<description>Name of the client</description>
<state readOnly="true"></state>
</channel-type>
<channel-type id="hostname">
<item-type>String</item-type>
<label>Hostname</label>
<description>Hostname of the client</description>
<state readOnly="true"></state>
</channel-type>
<channel-type id="site">
<item-type>String</item-type>
<label>Site Name</label>