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
//! The request half of the envelope.
use Serialize;
use ;
use crateResult;
/// A request to a bulb: a method name and its params.
///
/// `params` is always sent, as an empty object when there is nothing to say —
/// that is what the official app does (`{"method":"getPilot","params":{}}` in
/// the recorded traffic). Reads do not care either way; writes very much do,
/// and not in the direction you would guess: a `setPilot` with no `params` key
/// is refused with `-32602 Invalid params`, while the same request carrying
/// `"params":{}` is refused with `-32600 Invalid Request`. Both are meaningless
/// requests, so neither is worth building, but it does mean the two spellings
/// are not interchangeable.
///
/// There is deliberately no envelope-level `id`. Discovery puts `"id":"1"`
/// inside `registration`'s params, while the push registration the app sends
/// omits it; no reply echoes either form back, so it cannot match responses to
/// requests.
///
/// ```
/// use wizlight::Request;
///
/// let request = Request::new("getPilot");
/// assert_eq!(request.to_string(), r#"{"method":"getPilot","params":{}}"#);
///
/// let request = Request::with_params("setPilot", &serde_json::json!({"state": true}))?;
/// assert_eq!(request.to_string(), r#"{"method":"setPilot","params":{"state":true}}"#);
/// # Ok::<(), wizlight::Error>(())
/// ```