From 6d9cc49baa9498d1c8e0474568827d4836e7fba2 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Thu, 7 Nov 2024 06:46:30 +0100 Subject: [PATCH] [unifi] Provide LED channel for access point (#17702) * Provide LED channel for access Signed-off-by: Jacob Laursen --- bundles/org.openhab.binding.unifi/README.md | 1 + .../unifi/internal/UniFiBindingConstants.java | 1 + .../binding/unifi/internal/api/UniFiController.java | 11 +++++++++++ .../binding/unifi/internal/api/dto/UniFiDevice.java | 10 ++++++++-- .../handler/UniFiAccessPointThingHandler.java | 13 +++++++++++++ .../src/main/resources/OH-INF/i18n/unifi.properties | 2 ++ .../src/main/resources/OH-INF/thing/thing-types.xml | 6 +++++- .../main/resources/OH-INF/update/thing-updates.xml | 7 +++++++ 8 files changed, 48 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.unifi/README.md b/bundles/org.openhab.binding.unifi/README.md index ac97f78db57..a7241943012 100644 --- a/bundles/org.openhab.binding.unifi/README.md +++ b/bundles/org.openhab.binding.unifi/README.md @@ -249,6 +249,7 @@ The `accessPoint` information that is retrieved is available as these channels: | uptime | Number:Time | Uptime of the device (in seconds) | Read | | lastSeen | DateTime | Date and Time the device was last seen | Read | | experience | Number:Dimensionless | The average health indication of the connected clients | Read | +| led | Switch | Switch the LED on or off | Read, Write | ## Rule Actions diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiBindingConstants.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiBindingConstants.java index 35910b6fabd..ed758f7dc13 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiBindingConstants.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiBindingConstants.java @@ -100,6 +100,7 @@ public final class UniFiBindingConstants { // List of access point device channels public static final String CHANNEL_AP_ENABLE = "enable"; public static final String CHANNEL_AP_STATE = "state"; + public static final String CHANNEL_AP_LED = "led"; // List of all Parameters public static final String PARAMETER_HOST = "host"; diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiController.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiController.java index fa93d7bde87..6cce8ef220c 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiController.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiController.java @@ -224,6 +224,17 @@ public class UniFiController { refresh(); } + public void setLedOverride(final UniFiDevice device, final String override) throws UniFiException { + final UniFiControllerRequest req = newRequest(Void.class, HttpMethod.PUT, gson); + req.setAPIPath(String.format("/api/s/%s/rest/device/%s", device.getSite().getName(), device.getId())); + req.setBodyParameter("_id", device.getId()); + if (!override.isEmpty()) { + req.setBodyParameter("led_override", override); + } + executeRequest(req); + refresh(); + } + public void generateVouchers(final UniFiSite site, final int count, final int expiration, final int users, @Nullable Integer upLimit, @Nullable Integer downLimit, @Nullable Integer dataQuota) throws UniFiException { final UniFiControllerRequest req = newRequest(Void.class, HttpMethod.POST, gson); diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiDevice.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiDevice.java index 05ae2117060..5d03b09a613 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiDevice.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiDevice.java @@ -69,6 +69,8 @@ public class UniFiDevice implements HasId { private Boolean disabled; + private String ledOverride; + public UniFiDevice(final UniFiControllerCache cache) { this.cache = cache; } @@ -138,10 +140,14 @@ public class UniFiDevice implements HasId { return disabled; } + public String getLedOverride() { + return ledOverride; + } + @Override public String toString() { return String.format( - "UniFiDevice{mac: '%s', name: '%s', type: '%s', model: '%s', version: '%s', experience: %d, disabled: %b, uptime: %d, site: %s}", - mac, name, type, model, version, experience, disabled, uptime, getSite()); + "UniFiDevice{mac: '%s', name: '%s', type: '%s', model: '%s', version: '%s', experience: %d, disabled: %b, led: %s, uptime: %d, site: %s}", + mac, name, type, model, version, experience, disabled, ledOverride, uptime, getSite()); } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiAccessPointThingHandler.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiAccessPointThingHandler.java index a5b63aa2ae1..aa3c571f765 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiAccessPointThingHandler.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiAccessPointThingHandler.java @@ -152,6 +152,10 @@ public class UniFiAccessPointThingHandler extends UniFiBaseThingHandler(device.getExperience(), Units.PERCENT); } break; + case CHANNEL_AP_LED: + String override = device.getLedOverride(); + state = "default".equals(override) ? UnDefType.UNDEF : OnOffType.from(override); + break; } return state; } @@ -171,6 +175,8 @@ public class UniFiAccessPointThingHandler extends UniFiBaseThingHandler The average experience of the connected clients + + + Switches the LED on or off + Ubiquiti Networks - 1 + 2 diff --git a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/update/thing-updates.xml b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/update/thing-updates.xml index ed791001bbe..ff3f0bba3e8 100644 --- a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/update/thing-updates.xml +++ b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/update/thing-updates.xml @@ -36,6 +36,13 @@ The average experience of the connected clients + + + system:power + + Switches the LED on or off + +