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
//! `Client` methods for the `DevicesAPI` domain.
use super::Client;
use crate::cache::{Bucket, CacheKey};
use crate::envelope::Envelope;
use crate::error::Error;
impl Client {
/// Gets the list of connected devices — returns the raw Eero API response.
///
/// Ported from `get_devices()` (`eero-api src/eero/client.py:674-715` at `v8.0.4`);
/// `auto_discover = true` — see [`Client::get_network`] for the shared note. Passes the
/// cached network envelope as `parent=` (`+net`, `_network_parent_kwargs`).
///
/// `thread`/`proxied_node` are new since v6.2.0: `filtered = thread.is_some() ||
/// proxied_node.is_some()` gates **both** cache directions (`client.py:696-715`) — a
/// filtered call never reads the `devices[{nid}_devices]` cache, even if fresh, and never
/// writes it either, so a filtered response can never silently overwrite the unfiltered
/// cached list the next unfiltered call would otherwise read.
///
/// # Errors
///
/// See [`Client::get_network`].
pub async fn get_devices(
&self,
network_id: Option<&str>,
refresh_cache: bool,
thread: Option<bool>,
proxied_node: Option<bool>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let filtered = thread.is_some() || proxied_node.is_some();
let key = CacheKey::devices(network_id.as_str());
if !filtered
&& !refresh_cache
&& let Some(cached) = self.cache.get(&key)
{
return Ok(cached);
}
let parent = self.network_parent(network_id.as_str());
let response = self
.api
.devices()
.get_devices(&network_id, thread, proxied_node, parent.as_ref())
.await?;
if !filtered {
self.cache.put(key, response.clone());
}
Ok(response)
}
/// Gets a single device's full object — returns the raw Eero API response.
///
/// Ported from `get_device()` (`client.py:717-747`); see [`Client::get_network`] for the
/// shared `auto_discover = true` note. Note the parameter order: `device_id` (required)
/// comes first, `network_id` (optional) second — matching every cached getter that takes an
/// item id (brief §6). This call never passes `parent=` itself — it *populates* the cache
/// `Client::device_parent` later reads from.
///
/// # Errors
///
/// See [`Client::get_network`].
pub async fn get_device(
&self,
device_id: &str,
network_id: Option<&str>,
refresh_cache: bool,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let key = CacheKey::device(network_id.as_str(), device_id);
if !refresh_cache && let Some(cached) = self.cache.get(&key) {
return Ok(cached);
}
let response = self
.api
.devices()
.get_device(&network_id, device_id, None)
.await?;
self.cache.put(key, response.clone());
Ok(response)
}
/// Gets a single device's full object **without ever touching the cache** — returns the raw
/// Eero API response.
///
/// Ported from `get_device_priority()` (`client.py:2194-2200`): calls the exact same domain
/// method as [`Client::get_device`] (`DevicesApi::get_device`), but deliberately never reads
/// or writes `devices[{nid}_{did}]`, and resolves `network_id` with `auto_discover = false`
/// (`client.py:2199`) — unlike `get_device`, this method returns [`Error::MissingNetworkId`]
/// rather than probing `/networks` when no id/preferred network is set. **Do not** wire this
/// into the `devices` cache bucket to "fix" the apparent duplication with `get_device` — the
/// uncached-ness is the documented v8.0.4 behaviour, not an oversight
/// (`.claude/tasks/briefs/v8/client.md`, devices table, `get_device_priority` row).
///
/// # Errors
///
/// [`Error::MissingNetworkId`] if `network_id` is absent and no preferred network is set.
/// Otherwise, whatever status-mapped [`Error`] the request produces.
pub async fn get_device_priority(
&self,
device_id: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, false).await?;
self.api
.devices()
.get_device(&network_id, device_id, None)
.await
}
// ==================== Devices (mutations) ====================
/// Sets a nickname for a device — returns the raw Eero API response.
///
/// Ported from `set_device_nickname` (`eero-api src/eero/client.py:748-769`).
/// `auto_discover = true`. On success, invalidates both `devices[{nid}_{did}]` and
/// `devices[{nid}_devices]` via `Client::invalidate_device_cache`. No `parent=`.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
pub async fn set_device_nickname(
&self,
device_id: &str,
nickname: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.set_device_nickname(&network_id, device_id, nickname)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
/// Blocks a device via the `/blacklist` resource — returns the raw Eero API response.
///
/// Ported from `block_device` (`eero-api src/eero/client.py:770-789`). `auto_discover =
/// true`. **Breaking shape change**: the pre-8.0.0 `blocked: bool` parameter this crate
/// previously shipped is gone — unblocking is [`Client::unblock_device`], a separate method.
/// On success, invalidates both `devices[{nid}_{did}]` and `devices[{nid}_devices]`
/// (`client.py:786-787`). No `parent=`.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
pub async fn block_device(
&self,
device_id: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.block_device(&network_id, device_id)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
/// Unblocks a device via the `/blacklist` resource — returns the raw Eero API response.
///
/// Ported from `unblock_device` (`eero-api src/eero/client.py:790-809`). New since v6.2.0
/// (the pre-8.0.0 port folded this into `block_device(blocked: false)`). `auto_discover =
/// true`. On success, invalidates both `devices[{nid}_{did}]` and `devices[{nid}_devices]`,
/// same as [`Client::block_device`]. No `parent=`.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
pub async fn unblock_device(
&self,
device_id: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.unblock_device(&network_id, device_id)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
/// Pauses or unpauses internet access for a device — returns the raw Eero API response.
///
/// Ported from `pause_device` (`eero-api src/eero/client.py:810-831`). `auto_discover =
/// true`. On success, invalidates both `devices[{nid}_{did}]` and `devices[{nid}_devices]`.
/// No `parent=`.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
pub async fn pause_device(
&self,
device_id: &str,
paused: bool,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.pause_device(&network_id, device_id, paused)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
/// Updates a device's nickname/paused/profile via its own published URL — returns the raw
/// Eero API response.
///
/// Ported from `update_device_via_link` (`eero-api src/eero/client.py:832-867`).
/// `auto_discover = true`. Passes the cached single-device envelope as `parent=` (`+dev`,
/// `_device_parent_kwargs`). On success, invalidates both `devices[{nid}_{did}]` and
/// `devices[{nid}_devices]`, **and**, only when `profile` is `Some`, every cached profile
/// entry of this network (`Cache::invalidate_bucket(Bucket::Profiles, ..)`,
/// `client.py:1028-1038`'s `_invalidate_all_profile_caches` — a device's profile membership
/// changed, so nothing single-profile can be trusted any more).
///
/// # Errors
///
/// See [`Client::get_network`]. Also returns [`Error::Validation`] with `field: "device"` if
/// `nickname`, `paused` and `profile` are all `None`, before any request is sent. The cache
/// is left untouched on any `Err`.
pub async fn update_device_via_link(
&self,
device_id: &str,
nickname: Option<&str>,
paused: Option<bool>,
profile: Option<&str>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let parent = self.device_parent(network_id.as_str(), device_id);
let response = self
.api
.devices()
.update_device_via_link(
&network_id,
device_id,
nickname,
paused,
profile,
parent.as_ref(),
)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
if profile.is_some() {
self.cache
.invalidate_bucket(Bucket::Profiles, network_id.as_str());
}
Ok(response)
}
/// Sets a device's type — returns the raw Eero API response.
///
/// Ported from `set_device_type` (`eero-api src/eero/client.py:868-880`). `auto_discover =
/// true`. On success, invalidates both `devices[{nid}_{did}]` and `devices[{nid}_devices]`.
/// No `parent=`.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
pub async fn set_device_type(
&self,
device_id: &str,
device_type: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.set_device_type(&network_id, device_id, device_type)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
/// Gets a device's labels — returns the raw Eero API response.
///
/// Ported from `get_device_labels` (`eero-api src/eero/client.py:881-887`). `auto_discover =
/// true`. Not cached (only the eight getters in the behaviour brief §1.4 are).
///
/// # Errors
///
/// See [`Client::get_network`].
pub async fn get_device_labels(
&self,
device_id: &str,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
self.api
.devices()
.get_device_labels(&network_id, device_id)
.await
}
/// Sets a device's labels — returns the raw Eero API response.
///
/// Ported from `set_device_labels` (`eero-api src/eero/client.py:888-...`). `auto_discover =
/// true`. Confirmed server-side **no-op** as of 2026-09-20 (ported for parity, documented as
/// such — see [`crate::endpoints::devices::DevicesApi::set_device_labels`]). On success,
/// invalidates both `devices[{nid}_{did}]` and `devices[{nid}_devices]` regardless, matching
/// every other device write in this file.
///
/// # Errors
///
/// See [`Client::get_network`]. The cache is left untouched on any `Err`.
#[allow(clippy::too_many_arguments)]
pub async fn set_device_labels(
&self,
device_id: &str,
make_label: Option<&str>,
model_label: Option<&str>,
version_label: Option<&str>,
type_label: Option<&str>,
network_id: Option<&str>,
) -> Result<Envelope, Error> {
let network_id = self.ensure_network_id(network_id, true).await?;
let response = self
.api
.devices()
.set_device_labels(
&network_id,
device_id,
make_label,
model_label,
version_label,
type_label,
)
.await?;
self.invalidate_device_cache(network_id.as_str(), device_id);
Ok(response)
}
}