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
//! Updates API: `eero-api`'s `UpdatesAPI`.
//!
//! Ported from `eero-api src/eero/api/updates.py` (v8.0.4). `get_updates` existed at `v6.2.0`;
//! `apply_update` is new at v8.0.4.
use std::sync::Arc;
use serde_json::Value;
use crate::envelope::Envelope;
use crate::error::Error;
use crate::links::warn_uncharacterised_write;
use crate::routes;
use crate::transport::{RequestBody, Transport};
/// `eero-api`'s `UpdatesAPI` (`src/eero/api/updates.py`).
///
/// Build one with [`UpdatesApi::new`], wrapping a [`Transport`] already shared with the rest of
/// the `EeroApi` aggregator — `UpdatesApi` never constructs or owns a `Transport` itself.
#[derive(Debug)]
pub struct UpdatesApi {
transport: Arc<Transport>,
}
impl UpdatesApi {
/// Wraps `transport` as an `UpdatesApi`.
#[must_use]
pub fn new(transport: Arc<Transport>) -> Self {
Self { transport }
}
/// Gets available firmware/software updates for a network — returns the raw Eero API
/// response.
///
/// Ported from `eero-api src/eero/api/updates.py:35-60` (`UpdatesAPI.get_updates`). Sends
/// `GET` [`crate::routes::updates::GET_UPDATES_V8`], preferring `parent`'s own published
/// `updates` link.
///
/// # Errors
///
/// Returns [`Error::Validation`] if `network_id`/`parent` cannot be resolved to a URL.
/// Otherwise, [`Error::Authentication`] if no valid session is configured, or whatever
/// status-mapped [`Error`] the request produces.
pub async fn get_updates(
&self,
network_id: &str,
parent: Option<&Value>,
) -> Result<Envelope, Error> {
self.transport
.resource(
&routes::updates::GET_UPDATES_V8,
network_id,
parent,
&[],
RequestBody::None,
)
.await
}
/// Applies a pending update — returns the raw Eero API response.
///
/// Ported from `eero-api src/eero/api/updates.py:65-98` (`UpdatesAPI.apply_update`). Sends
/// the literal two-byte body `""` ([`RequestBody::EmptyJsonString`]) to
/// [`crate::routes::updates::UPDATES_APPLY_UPDATE`], preferring `parent`'s own published `updates`
/// link. **Reboot-class write**: applying an update reboots every node on the network.
/// Unverified against a live network: logs one `WARNING` via [`warn_uncharacterised_write`]
/// before issuing the request (`updates.py:97`).
///
/// # Errors
///
/// See [`UpdatesApi::get_updates`].
pub async fn apply_update(
&self,
network_id: &str,
parent: Option<&Value>,
) -> Result<Envelope, Error> {
let url = routes::updates::UPDATES_APPLY_UPDATE.resolve(
self.transport.api_host(),
network_id,
parent,
)?;
warn_uncharacterised_write("apply update for network — reboots every node");
self.transport
.request(
routes::updates::UPDATES_APPLY_UPDATE.method.clone(),
url,
&[],
RequestBody::EmptyJsonString,
)
.await
}
}