unifly_api/controller/query/
inventory.rs1use crate::core_error::CoreError;
2use crate::model::{EntityId, WifiBroadcast};
3
4use super::super::{Controller, integration_site_context, require_uuid};
5
6impl Controller {
7 pub async fn get_wifi_broadcast_detail(
8 &self,
9 id: &EntityId,
10 ) -> Result<WifiBroadcast, CoreError> {
11 let (client, site_id) = integration_site_context(self, "get_wifi_broadcast_detail").await?;
12 let uuid = require_uuid(id)?;
13 let detail = client.get_wifi_broadcast(&site_id, &uuid).await?;
14 Ok(WifiBroadcast::from(detail))
15 }
16
17 pub async fn list_pending_devices(&self) -> Result<Vec<serde_json::Value>, CoreError> {
18 let integration = self.inner.integration_client.lock().await.clone();
19 let site_id = *self.inner.site_id.lock().await;
20
21 if let (Some(client), Some(site_id)) = (integration, site_id) {
22 let raw = client
23 .paginate_all(200, |offset, limit| {
24 client.list_pending_devices(&site_id, offset, limit)
25 })
26 .await?;
27 return Ok(raw
28 .into_iter()
29 .map(|value| serde_json::to_value(value).unwrap_or_default())
30 .collect());
31 }
32
33 let snapshot = self.devices_snapshot();
34 Ok(snapshot
35 .iter()
36 .filter(|device| device.state == crate::model::DeviceState::PendingAdoption)
37 .map(|device| serde_json::to_value(device.as_ref()).unwrap_or_default())
38 .collect())
39 }
40
41 pub async fn list_device_tags(&self) -> Result<Vec<serde_json::Value>, CoreError> {
42 let integration = self.inner.integration_client.lock().await.clone();
43 let site_id = *self.inner.site_id.lock().await;
44
45 if let (Some(client), Some(site_id)) = (integration, site_id) {
46 let raw = client
47 .paginate_all(200, |offset, limit| {
48 client.list_device_tags(&site_id, offset, limit)
49 })
50 .await?;
51 return Ok(raw
52 .into_iter()
53 .map(|value| serde_json::to_value(value).unwrap_or_default())
54 .collect());
55 }
56
57 Ok(Vec::new())
58 }
59}