Skip to content

Commit

Permalink
[unifi] Provide LED channel for access point (#17702)
Browse files Browse the repository at this point in the history
* Provide LED channel for access

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored Nov 7, 2024
1 parent f37f39c commit 6d9cc49
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.unifi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class UniFiDevice implements HasId {

private Boolean disabled;

private String ledOverride;

public UniFiDevice(final UniFiControllerCache cache) {
this.cache = cache;
}
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 6d9cc49

Please sign in to comment.