unifly_api/integration/client/
devices.rs1use serde::Serialize;
2use uuid::Uuid;
3
4use super::{Error, IntegrationClient, types};
5
6impl IntegrationClient {
7 pub async fn list_devices(
10 &self,
11 site_id: &Uuid,
12 offset: i64,
13 limit: i32,
14 ) -> Result<types::Page<types::DeviceResponse>, Error> {
15 self.get_with_params(
16 &format!("v1/sites/{site_id}/devices"),
17 &[("offset", offset.to_string()), ("limit", limit.to_string())],
18 )
19 .await
20 }
21
22 pub async fn get_device(
23 &self,
24 site_id: &Uuid,
25 device_id: &Uuid,
26 ) -> Result<types::DeviceDetailsResponse, Error> {
27 self.get(&format!("v1/sites/{site_id}/devices/{device_id}"))
28 .await
29 }
30
31 pub async fn get_device_statistics(
32 &self,
33 site_id: &Uuid,
34 device_id: &Uuid,
35 ) -> Result<types::DeviceStatisticsResponse, Error> {
36 self.get(&format!(
37 "v1/sites/{site_id}/devices/{device_id}/statistics/latest"
38 ))
39 .await
40 }
41
42 pub async fn adopt_device(
43 &self,
44 site_id: &Uuid,
45 mac: &str,
46 ignore_device_limit: bool,
47 ) -> Result<types::DeviceDetailsResponse, Error> {
48 #[derive(Serialize)]
49 #[serde(rename_all = "camelCase")]
50 struct Body<'a> {
51 mac_address: &'a str,
52 ignore_device_limit: bool,
53 }
54
55 self.post(
56 &format!("v1/sites/{site_id}/devices"),
57 &Body {
58 mac_address: mac,
59 ignore_device_limit,
60 },
61 )
62 .await
63 }
64
65 pub async fn remove_device(&self, site_id: &Uuid, device_id: &Uuid) -> Result<(), Error> {
66 self.delete(&format!("v1/sites/{site_id}/devices/{device_id}"))
67 .await
68 }
69
70 pub async fn device_action(
71 &self,
72 site_id: &Uuid,
73 device_id: &Uuid,
74 action: &str,
75 ) -> Result<(), Error> {
76 #[derive(Serialize)]
77 struct Body<'a> {
78 action: &'a str,
79 }
80
81 self.post_no_response(
82 &format!("v1/sites/{site_id}/devices/{device_id}/actions"),
83 &Body { action },
84 )
85 .await
86 }
87
88 pub async fn port_action(
89 &self,
90 site_id: &Uuid,
91 device_id: &Uuid,
92 port_idx: u32,
93 action: &str,
94 ) -> Result<(), Error> {
95 #[derive(Serialize)]
96 struct Body<'a> {
97 action: &'a str,
98 }
99
100 self.post_no_response(
101 &format!("v1/sites/{site_id}/devices/{device_id}/interfaces/ports/{port_idx}/actions"),
102 &Body { action },
103 )
104 .await
105 }
106
107 pub async fn list_pending_devices(
108 &self,
109 _site_id: &Uuid,
110 offset: i64,
111 limit: i32,
112 ) -> Result<types::Page<types::PendingDeviceResponse>, Error> {
113 self.get_with_params(
114 "v1/pending-devices",
115 &[("offset", offset.to_string()), ("limit", limit.to_string())],
116 )
117 .await
118 }
119
120 pub async fn list_device_tags(
121 &self,
122 site_id: &Uuid,
123 offset: i64,
124 limit: i32,
125 ) -> Result<types::Page<types::DeviceTagResponse>, Error> {
126 self.get_with_params(
127 &format!("v1/sites/{site_id}/device-tags"),
128 &[("offset", offset.to_string()), ("limit", limit.to_string())],
129 )
130 .await
131 }
132}