Skip to main content

unifly_api/session/
wifi.rs

1// Session API Wi-Fi observability endpoints
2//
3// Covers neighboring AP scans, regulatory channel availability, and
4// per-client Wi-Fi experience metrics from the v2 wifiman surface.
5
6use serde_json::Value;
7use tracing::debug;
8
9use crate::error::Error;
10use crate::session::client::SessionClient;
11use crate::session::models::{ChannelAvailability, RogueAp};
12
13impl SessionClient {
14    /// List neighboring / rogue access points detected by your APs.
15    ///
16    /// `GET /api/s/{site}/stat/rogueap`
17    ///
18    /// **Quirk:** `within_secs` uses Unix epoch seconds semantics, not
19    /// milliseconds like many other UniFi stats routes.
20    pub async fn list_rogue_aps(&self, within_secs: Option<i64>) -> Result<Vec<RogueAp>, Error> {
21        let path = match within_secs {
22            Some(secs) => format!("stat/rogueap?within={secs}"),
23            None => "stat/rogueap".to_string(),
24        };
25        let url = self.site_url(&path);
26        debug!(?within_secs, "listing rogue and neighboring APs");
27        self.get(url).await
28    }
29
30    /// List per-radio regulatory channel availability.
31    ///
32    /// `GET /api/s/{site}/stat/current-channel`
33    pub async fn list_channels(&self) -> Result<Vec<ChannelAvailability>, Error> {
34        let url = self.site_url("stat/current-channel");
35        debug!("listing regulatory channel availability");
36        self.get(url).await
37    }
38
39    /// Get per-client live Wi-Fi experience metrics.
40    ///
41    /// `GET /v2/api/site/{site}/wifiman/{client_ip}/`
42    ///
43    /// **Quirk:** Band codes from this endpoint (`2.4g`, `5g`, `6g`)
44    /// differ from `stat/sta` (`ng`, `na`, `6e`).
45    pub async fn get_client_wifi_experience(&self, client_ip: &str) -> Result<Value, Error> {
46        let path = format!("wifiman/{client_ip}/");
47        let url = self.site_url_v2(&path);
48        debug!(client_ip, "fetching client Wi-Fi experience");
49        self.get_raw(url).await
50    }
51}