1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
//! `Client` methods for the `DataUsageAPI` domain.
//!
//! None of these twelve methods is ever cached (the whole family is time-windowed reads, not one
//! of the eight cached getters) and every one passes `auto_discover = false`. None of them
//! passes `parent=` at this layer either — `EeroClient` never supplies one for this family, even
//! when a network envelope is cached; the underlying domain methods still accept `parent=` for
//! a caller reaching `client.api().data_usage()` directly with its own cached envelope.
//!
//! The ten time-windowed reads take `timeout: Option<RequestTimeout>` immediately before the
//! trailing `network_id` and forward it unchanged to the matching `DataUsageApi` read
//! (`client.py:2056,2077`); `get_data_usage_report_settings` and
//! `set_data_usage_report_settings` do not. Every `client.py` citation in this file is to
//! `v8.4.1`.
use super::Client;
use crate::cache::CacheKey;
use crate::envelope::Envelope;
use crate::error::Error;
use crate::transport::RequestTimeout;
impl Client {
/// Gets network-wide data-usage statistics — returns the raw Eero API response.
///
/// Ported from `get_data_usage()` (`eero-api src/eero/client.py:2048-2078` at `v8.4.1`).
/// **Breaking shape change** from the pre-8.0.0 port this crate previously shipped: the old
/// `payload`/`resource` parameters are gone, replaced by required `start`/`end`/`cadence` and
/// optional `timezone`. `auto_discover = false`.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_data_usage(
&self,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_data_usage(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets a data-usage breakdown by category — returns the raw Eero API response.
///
/// Ported from `get_data_usage_breakdown()` (`eero-api src/eero/client.py:2080-2098`).
/// `auto_discover = false`. `cadence` is optional.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_data_usage_breakdown(
&self,
start: &str,
end: &str,
cadence: Option<&str>,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_breakdown(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets data-usage statistics for every device on a network — returns the raw Eero API
/// response.
///
/// Ported from `get_devices_data_usage()` (`eero-api src/eero/client.py:2100-2125`).
/// `auto_discover = false`. `cadence`/`profile_id` are optional.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_devices_data_usage(
&self,
start: &str,
end: &str,
cadence: Option<&str>,
timezone: Option<&str>,
profile_id: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_devices_usage(
&network_id,
start,
end,
cadence,
timezone,
profile_id,
timeout,
None,
)
.await
}
/// Gets data-usage statistics for a single device — returns the raw Eero API response.
///
/// Ported from `get_device_data_usage()` (`eero-api src/eero/client.py:2127-2152`).
/// `auto_discover = false`. `cadence` is required.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_device_data_usage(
&self,
device_mac: &str,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_device_usage(
&network_id,
device_mac,
start,
end,
cadence,
timezone,
timeout,
None,
)
.await
}
/// Gets an aggregated data-usage summary across every eero on a network — returns the raw
/// Eero API response.
///
/// Ported from `get_eeros_data_usage_summary()` (`eero-api src/eero/client.py:2174-2192`).
/// `auto_discover = false`. `cadence` is required.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_eeros_data_usage_summary(
&self,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_eeros_summary(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets data-usage statistics for every eero on the network — returns the raw Eero API
/// response.
///
/// Ported from `get_eeros_data_usage()` (`eero-api src/eero/client.py:2154-2172` at
/// `v8.4.1`), a thin wrapper over [`crate::endpoints::data_usage::DataUsageApi::get_eeros_usage`]
/// (`GET /2.2/networks/{id}/data_usage/eeros`). `auto_discover = false`. `cadence` is
/// required. Not cached, and invalidates nothing, so every call reaches the API. No `parent=`
/// is forwarded, even when a network envelope is cached. Distinct from
/// [`Client::get_eeros_data_usage_summary`] (`.../data_usage/eeros/summary`) and
/// [`Client::get_eero_data_usage`] (`.../data_usage/eeros/{eero_id}`).
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
pub async fn get_eeros_data_usage(
&self,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_eeros_usage(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets data-usage statistics for a single eero — returns the raw Eero API response.
///
/// Ported from `get_eero_data_usage()` (`eero-api src/eero/client.py:2194-2219`).
/// `auto_discover = false`. `cadence` is required.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_eero_data_usage(
&self,
eero_id: &str,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_eero_usage(
&network_id,
eero_id,
start,
end,
cadence,
timezone,
timeout,
None,
)
.await
}
/// Gets data-usage statistics for a single profile — returns the raw Eero API response.
///
/// Ported from `get_profile_data_usage()` (`eero-api src/eero/client.py:2221-2246`).
/// `auto_discover = false`. `cadence` is required.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_profile_data_usage(
&self,
profile_id: &str,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_profile_usage(
&network_id,
profile_id,
start,
end,
cadence,
timezone,
timeout,
None,
)
.await
}
/// Gets data-usage statistics for devices with no profile — returns the raw Eero API
/// response.
///
/// Ported from `get_unprofiled_devices_data_usage()` (`eero-api src/eero/client.py:2248-2266`).
/// `auto_discover = false`. `cadence` is optional.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_unprofiled_devices_data_usage(
&self,
start: &str,
end: &str,
cadence: Option<&str>,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_unprofiled_devices(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets an aggregated data-usage summary for unprofiled devices — returns the raw Eero API
/// response.
///
/// Ported from `get_unprofiled_data_usage_summary()` (`eero-api src/eero/client.py:2268-2286`).
/// `auto_discover = false`. `cadence` is required.
///
/// `timeout`, when `Some`, replaces the transport default for this request only (see
/// [`RequestTimeout`]); `None` keeps it.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
#[allow(clippy::too_many_arguments)]
pub async fn get_unprofiled_data_usage_summary(
&self,
start: &str,
end: &str,
cadence: &str,
timezone: Option<&str>,
timeout: Option<RequestTimeout>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_unprofiled_summary(&network_id, start, end, cadence, timezone, timeout, None)
.await
}
/// Gets the network's data-usage report settings — returns the raw Eero API response.
///
/// Ported from `get_data_usage_report_settings()` (`eero-api src/eero/client.py:2288-2296`).
/// `auto_discover = false`. No query parameters at all.
///
/// # Errors
///
/// See [`Client::get_diagnostics`].
pub async fn get_data_usage_report_settings(
&self,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.data_usage()
.get_report_settings(&network_id, None)
.await
}
/// Sets the network's data-usage report settings — returns the raw Eero API response.
///
/// Ported from `set_data_usage_report_settings()` (`eero-api src/eero/client.py:2298-2318`),
/// the only write in this family. `auto_discover = false`. On success, invalidates
/// `network[{nid}]`.
///
/// # Errors
///
/// See [`Client::get_diagnostics`]. The cache is left untouched on any `Err`.
pub async fn set_data_usage_report_settings(
&self,
cadence: &str,
notification_day: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
let response = self
.api
.data_usage()
.set_report_settings(&network_id, cadence, notification_day, None)
.await?;
self.cache
.invalidate(&CacheKey::network(network_id.as_str()));
Ok(response)
}
}