google_smart_home/
execute.rs

1use crate::device::Command;
2use serde::Deserialize;
3use serde::Serialize;
4
5/// Request types of the EXECUTE intent
6pub mod request {
7    use super::*;
8
9    /// EXECUTE request payload.
10    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
11    #[serde(rename_all = "camelCase")]
12    pub struct Payload {
13        /// List of device target and command pairs.
14        pub commands: Vec<PayloadCommand>,
15    }
16
17    /// Set of commands to execute on the attached device targets.
18    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
19    #[serde(rename_all = "camelCase")]
20    pub struct PayloadCommand {
21        /// List of target devices.
22        pub devices: Vec<PayloadCommandDevice>,
23        /// List of commands to execute on target devices.
24        pub execution: Vec<PayloadCommandExecution>,
25    }
26
27    /// Device target to execute.
28    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
29    #[serde(rename_all = "camelCase")]
30    pub struct PayloadCommandDevice {
31        /// Device ID, as per the ID provided in SYNC.
32        pub id: String,
33        /// If the opaque customData object is provided in SYNC, it's sent here.
34        #[serde(default)]
35        pub custom_data: serde_json::Map<String, serde_json::Value>,
36    }
37
38    /// Device command.
39    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
40    #[serde(rename_all = "camelCase")]
41    pub struct PayloadCommandExecution {
42        /// The command to execute, usually with accompanying parameters.
43        #[serde(flatten)]
44        pub command: Command,
45    }
46}
47
48/// Response types of the EXECUTE intent
49pub mod response {
50    use super::*;
51
52    /// EXECUTE response.
53    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
54    #[serde(rename_all = "camelCase")]
55    pub struct Response {
56        pub request_id: String,
57        pub payload: Payload,
58    }
59
60    /// EXECUTE response payload.
61    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
62    #[serde(rename_all = "camelCase")]
63    pub struct Payload {
64        /// An error code for the entire transaction for auth failures and developer system unavailability.
65        /// For individual device errors, use the errorCode within the device object.
66        pub error_code: Option<String>,
67        /// Detailed error which will never be presented to users but may be logged or used during development.
68        pub debug_string: Option<String>,
69        /// Each object contains one or more devices with response details. N.B.
70        /// These may not be grouped the same way as in the request.
71        /// For example, the request might turn 7 lights on, with 3 lights succeeding and 4 failing, thus with two groups in the response
72        pub commands: Vec<PayloadCommand>,
73    }
74
75    /// Device execution result.
76    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
77    #[serde(rename_all = "camelCase")]
78    pub struct PayloadCommand {
79        /// List of device IDs corresponding to this status.
80        pub ids: Vec<String>,
81        /// Result of the execute operation.
82        pub status: PayloadCommandStatus,
83        /// Aligned with per-trait states described in each trait schema reference.
84        /// These are the states after execution, if available.
85        #[serde(default)]
86        #[serde(skip_serializing_if = "serde_json::Map::is_empty")]
87        pub states: serde_json::Map<String, serde_json::Value>,
88        /// Expanding ERROR state if needed from the preset error codes, which will map to the errors presented to users.
89        #[serde(skip_serializing_if = "Option::is_none")]
90        pub error_code: Option<String>,
91    }
92
93    /// Result of the execute operation.
94    #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
95    #[repr(u8)]
96    #[serde(rename_all = "UPPERCASE")]
97    pub enum PayloadCommandStatus {
98        /// Confirm that the command succeeded.
99        Success,
100        /// Command is enqueued but expected to succeed.
101        Pending,
102        /// Target device is in offline state or unreachable.
103        Offline,
104        /// There is an issue or alert associated with a command.
105        /// The command could succeed or fail.
106        /// This status type is typically set when you want to send additional information about another connected device.
107        Exceptions,
108        /// Target device is unable to perform the command.
109        Error,
110    }
111}