[unifi] Provide LED channel for access point (#17702)

* Provide LED channel for access

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-11-07 06:46:30 +01:00 committed by Ciprian Pascu
parent 48ae1e267b
commit 5f0e3c438c
8 changed files with 48 additions and 3 deletions

View File

@ -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

View File

@ -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";

View File

@ -224,6 +224,17 @@ public class UniFiController {
refresh();
}
public void setLedOverride(final UniFiDevice device, final String override) throws UniFiException {
final UniFiControllerRequest<Void> 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<Void> req = newRequest(Void.class, HttpMethod.POST, gson);

View File

@ -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());
}
}

View File

@ -152,6 +152,10 @@ public class UniFiAccessPointThingHandler extends UniFiBaseThingHandler<UniFiDev
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 @@ public class UniFiAccessPointThingHandler extends UniFiBaseThingHandler<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 @@ public class UniFiAccessPointThingHandler extends UniFiBaseThingHandler<UniFiDev
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;
}
}

View File

@ -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)

View File

@ -171,11 +171,15 @@
<channel id="experience" typeId="experience">
<description>The average experience of the connected clients</description>
</channel>
<channel id="led" typeId="system.power">
<label>LED</label>
<description>Switches the LED on or off</description>
</channel>
</channels>
<properties>
<property name="vendor">Ubiquiti Networks</property>
<property name="thingTypeVersion">1</property>
<property name="thingTypeVersion">2</property>
</properties>
<config-description-ref uri="thing-type:unifi:accessPoint"/>

View File

@ -36,6 +36,13 @@
<description>The average experience of the connected clients</description>
</add-channel>
</instruction-set>
<instruction-set targetVersion="2">
<add-channel id="led">
<type>system:power</type>
<label>LED</label>
<description>Switches the LED on or off</description>
</add-channel>
</instruction-set>
</thing-type>
</update:update-descriptions>