]> git.basschouten.com Git - openhab-addons.git/commitdiff
[unifi] Added channels name and hostname to client things. (#14283)
authorHilbrand Bouwkamp <hilbrand@h72.nl>
Mon, 30 Jan 2023 07:59:19 +0000 (08:59 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 07:59:19 +0000 (08:59 +0100)
* [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>
bundles/org.openhab.binding.unifi/README.md
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiBindingConstants.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/cache/UniFiCache.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/cache/UniFiClientCache.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiClient.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiSiteThingHandler.java
bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiThingDiscoveryService.java
bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/i18n/unifi.properties
bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml

index fb812a2e26b84dcaeb055d46fa1513f6f44dba12..6eeebae1ce86e9bd232f944b8c3dca576a166271 100644 (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        |
index 7d36ef133c0536f593c858ddf4e406d04b35fa6e..6d92947d58da6cee7a2ee19873c1e77669ede385 100644 (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";
index 04dc87963be40595e93f7f7f07f89c6e9db26f93..04ba7a3c6ffee4e6a8260054e4d9a5678027d484 100644 (file)
@@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
 abstract class UniFiCache<T extends @Nullable HasId> {
 
     public enum Prefix {
-        ALIAS,
         DESC,
         HOSTNAME,
         ID,
index 6db44d40cf8fd719ea947aee148be7edfe5b0ccf..3dfc3bc07c4bf042af69aab8c919dc15800b8868 100644 (file)
  */
 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();
+    }
 }
index 109ad1efcba150f55027140477b567c3094a1f9d..1c77a557243bfa07d341d395c3541757f428009f 100644 (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());
     }
 }
index 6d01b482959238c01a21d58fc40c10221dc1b4d9..cf1be9bc9c8669497c70db9ea6cb6ac46b131798 100644 (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()) {
index 2fa53634903a7a8075d1b9cc9b843c9b5c7266bc..5234fc49134d5ce6a178a33285964abf56f1f758 100644 (file)
  */
 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();
index 5568b3ec4cff6fc650ee95e19d7585b77e723e54..46aeace7017a9662b0ddc96444e01b8ce89c2955 100644 (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());
         }
     }
 
index fdd76010d2c127f42faf5deecf2a08d70cb9554f..cf85fda2973a78f3ce2037c139994c5401629f41 100644 (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>
index b4ed105ef34e1584b331a04725aa025ff1dffe89..ee1b74edaa9fb424d3832deddb13fc6e0734e967 100644 (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.
index 640a10e51109baa895eb700267153cf4b959be52..bce8ac886dfd5e908d8a417a531b1380f621d1ef 100644 (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"/>
                <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>