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
//! `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:927-969` at `v8.4.1`);
/// `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 — 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. An unfiltered response is stored only if no cache invalidation ran
/// while the request was in flight.
///
/// # 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 generation = self.cache.generation();
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_if_current(key, response.clone(), generation);
}
Ok(response)
}
/// Gets a single device's full object — returns the raw Eero API response.
///
/// Ported from `get_device()` (`client.py:971-1001` at `v8.4.1`); 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. This call never passes `parent=` itself — it *populates* the cache
/// `Client::device_parent` later reads from.
///
/// The entry is cached under a canonical key: the last path segment of `device_id`, and, when
/// that is a MAC address in any spelling (`aabbccddeeff`, `AA:BB:CC:DD:EE:FF`,
/// `aa-bb-cc-dd-ee-ff`, `aabb.ccdd.eeff`), its lowercase hex digits. A bare id, a path
/// and an absolute URL for the same device therefore share one entry, while the request
/// itself still carries `device_id` exactly as written. The response is stored only if no
/// cache invalidation ran while the request was in flight.
///
/// # Errors
///
/// [`Error::Validation`] with `field: "id_or_url"` if `device_id` is empty, before the device
/// request is sent. The network is resolved first, as in Python, so with no `network_id` and
/// no preferred network auto-discovery may still read `/networks`. Otherwise 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 = Self::device_cache_key(network_id.as_str(), device_id)?;
if !refresh_cache && let Some(cached) = self.cache.get(&key) {
return Ok(cached);
}
let generation = self.cache.generation();
let response = self
.api
.devices()
.get_device(&network_id, device_id, None)
.await?;
self.cache.put_if_current(key, response.clone(), generation);
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.
///
/// # 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:1003-1023` at `v8.4.1`).
/// `auto_discover = true`. On success, invalidates both the device's entry (through its
/// canonical key, so a write under any spelling drops the entry read under another) 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:1025-1043` at `v8.4.1`).
/// `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 the device's
/// entry (through its canonical key) and `devices[{nid}_devices]`. No `parent=`. The write
/// was live-verified upstream on 2026-10-06 and logs no uncharacterised-write warning.
///
/// An empty `device_id` is rejected before the write is sent. Python's block write has no
/// check of its own: it posts `mac=`, and only afterwards fails to derive the cache key,
/// reporting a validation error for a write the server accepted and leaving the device list
/// cached. Failing first reports the same error without sending the write. The network is
/// resolved before that check, as in Python, so with no `network_id` and no preferred
/// network auto-discovery may still read `/networks` first.
///
/// # Errors
///
/// [`Error::Validation`] with `field: "id_or_url"` if `device_id` is empty, before the write
/// is sent (auto-discovery may still read `/networks` first). Otherwise 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?;
// The cache key is derived up front: an id that has none (an empty one) is rejected here,
// before the write goes out.
Self::device_cache_key(network_id.as_str(), device_id)?;
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:1045-1063` at `v8.4.1`). 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 the device's entry (through its
/// canonical key) 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:1065-1085` at `v8.4.1`).
/// `auto_discover = true`. On success, invalidates both the device's entry (through its
/// canonical key) 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:1087-1121` at
/// `v8.4.1`). `auto_discover = true`. Passes the cached single-device envelope as `parent=`
/// (`+dev`, `_device_parent_kwargs`), found through the canonical key, so an envelope cached
/// under any spelling of the device is reused. On success, invalidates both the device's
/// entry (through its canonical key) and `devices[{nid}_devices]`, **and**, only when
/// `profile` is `Some`, every cached profile entry of this network
/// (`Cache::invalidate_bucket(Bucket::Profiles, ..)`, `_invalidate_all_profile_caches` — a
/// device's profile membership changed, so nothing single-profile can be trusted any more).
///
/// # Errors
///
/// [`Error::Validation`] with `field: "id_or_url"` if `device_id` is empty, before the device
/// request is sent and ahead of the check below. Otherwise see [`Client::get_network`]. Also
/// returns [`Error::Validation`] with `field: "device"` if `nickname`, `paused` and `profile`
/// are all `None`, before the device request is sent. Both checks run after the network is
/// resolved, as in Python, so with no `network_id` and no preferred network auto-discovery
/// may still read `/networks` first. 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:1123-1134` at `v8.4.1`).
/// `auto_discover = true`. On success, invalidates both the device's entry (through its
/// canonical key) 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 cached getters listed in [`crate::client`] 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:1143-1171` at `v8.4.1`).
/// `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
/// the device's entry (through its canonical key) 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)
}
}