* [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>
| 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 |
| 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 |
// 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";
abstract class UniFiCache<T extends @Nullable HasId> {
public enum Prefix {
- ALIAS,
DESC,
HOSTNAME,
ID,
*/
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;
* {@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
*/
class UniFiClientCache extends UniFiCache<UniFiClient> {
public UniFiClientCache() {
- super(ID, MAC, IP, HOSTNAME, ALIAS);
+ super(ID, MAC, IP, HOSTNAME, NAME);
}
@Override
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();
+ }
}
private String ip;
- @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
private String hostname;
- @SerializedName("name")
- @JsonAdapter(UniFiTidyLowerCaseStringDeserializer.class)
- private String alias;
+ private String name;
private Integer uptime;
return hostname;
}
- public String getAlias() {
- return alias;
+ public String getName() {
+ return name;
}
public Integer getUptime() {
@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());
}
}
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;
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()) {
*/
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;
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:
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();
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withBridge(bridgeUID)
.withRepresentationProperty(PARAMETER_CID).withTTL(TTL_SECONDS).withProperties(properties)
- .withLabel(uc.getAlias()).build());
+ .withLabel(uc.getName()).build());
}
}
<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>
# 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
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
# 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
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.
<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"/>
<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"/>
<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>