diff --git a/bundles/org.openhab.binding.unifi/README.md b/bundles/org.openhab.binding.unifi/README.md index ac97f78db57cf..a7241943012d0 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 35910b6fabd65..ed758f7dc13e4 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 fa93d7bde8752..6cce8ef220cf2 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 void disableAccessPoint(final UniFiDevice device, final boolean disable) 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 05ae21170609f..5d03b09a613bd 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 Boolean isDisabled() { 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 a5b63aa2ae118..aa3c571f76530 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 @@ protected State getChannelState(final UniFiDevice device, final String channelId state = new QuantityType<>(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 @@ protected boolean handleCommand(final UniFiController controller, final UniFiDev if (CHANNEL_AP_ENABLE.equals(channelID) && command instanceof OnOffType onOffCommand) { return handleEnableCommand(controller, device, channelUID, onOffCommand); + } else if (CHANNEL_AP_LED.equals(channelID) && command instanceof OnOffType onOffCommand) { + return handleLedCommand(controller, device, channelUID, onOffCommand); } return false; } @@ -181,4 +187,11 @@ private boolean handleEnableCommand(final UniFiController controller, final UniF refresh(); return true; } + + private boolean handleLedCommand(final UniFiController controller, final UniFiDevice device, + final ChannelUID channelUID, final OnOffType command) throws UniFiException { + controller.setLedOverride(device, command == OnOffType.ON ? "on" : "off"); + refresh(); + return true; + } } diff --git a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/i18n/unifi.properties b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/i18n/unifi.properties index ade8ed542954b..7ff47f8183c37 100644 --- a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/i18n/unifi.properties +++ b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/i18n/unifi.properties @@ -10,6 +10,8 @@ thing-type.unifi.accessPoint.description = An access point managed by a UniFi co thing-type.unifi.accessPoint.channel.experience.description = The average experience of the connected clients thing-type.unifi.accessPoint.channel.ipAddress.description = IP address of the device thing-type.unifi.accessPoint.channel.lastSeen.description = Timestamp of when the device was last seen +thing-type.unifi.accessPoint.channel.led.label = LED +thing-type.unifi.accessPoint.channel.led.description = Switches the LED on or off thing-type.unifi.accessPoint.channel.name.description = Name of the device thing-type.unifi.accessPoint.channel.online.description = Online status of the device thing-type.unifi.accessPoint.channel.uptime.description = Uptime of the device (in seconds) diff --git a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml index 2586fa5095331..8a173dc45d133 100644 --- a/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.unifi/src/main/resources/OH-INF/thing/thing-types.xml @@ -171,11 +171,15 @@ 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 ed791001bbe4c..ff3f0bba3e8c7 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 + +