Skip to main content

huawei_dongle_api/api/
monitoring.rs

1//! Monitoring API endpoints
2
3use crate::{
4    client::Client,
5    error::{Error, Result},
6    models::monitoring::MonitoringStatus,
7};
8use tracing::{debug, trace};
9
10/// Monitoring API for status and signal monitoring
11pub struct MonitoringApi<'a> {
12    client: &'a Client,
13}
14
15impl<'a> MonitoringApi<'a> {
16    pub fn new(client: &'a Client) -> Self {
17        Self { client }
18    }
19
20    pub async fn status(&self) -> Result<MonitoringStatus> {
21        debug!("Fetching monitoring status");
22
23        self.client
24            .get_authenticated_with_retry("/api/monitoring/status", |text| {
25                trace!("Monitoring status response: {}", text);
26                let status: MonitoringStatus = serde_xml_rs::from_str(text).map_err(|e| {
27                    Error::generic(format!("Failed to parse monitoring status: {e}"))
28                })?;
29
30                debug!(
31                    "Monitoring status parsed: connection={}, network={}, signal={}",
32                    status.connection_status_text(),
33                    status.network_type_text(),
34                    status.signal_level().unwrap_or(0)
35                );
36
37                Ok(status)
38            })
39            .await
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46    use crate::config::Config;
47
48    #[test]
49    fn test_monitoring_api_creation() {
50        let config = Config::default();
51        let client = crate::Client::new(config).unwrap();
52        let monitoring_api = client.monitoring();
53
54        assert_eq!(
55            std::mem::size_of_val(&monitoring_api),
56            std::mem::size_of::<&Client>()
57        );
58    }
59}