google_smart_home/
query.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4pub mod request {
5    use super::*;
6
7    /// QUERY request payload.
8    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
9    #[serde(rename_all = "camelCase")]
10    pub struct Payload {
11        /// List of target devices.
12        pub devices: Vec<PayloadDevice>,
13    }
14
15    /// QUERY request payload.
16    #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
17    #[serde(rename_all = "camelCase")]
18    pub struct PayloadDevice {
19        /// Device ID, as per the ID provided in SYNC.
20        pub id: String,
21
22        /// If the opaque customData object is provided in SYNC, it's sent here.
23        pub custom_data: Option<serde_json::Map<String, serde_json::Value>>,
24    }
25}
26
27pub mod response {
28    use super::*;
29
30    /// QUERY response.
31    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
32    #[serde(rename_all = "camelCase")]
33    pub struct Response {
34        pub request_id: String,
35        pub payload: Payload,
36    }
37
38    /// QUERY response payload.
39    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
40    #[serde(rename_all = "camelCase")]
41    pub struct Payload {
42        /// An error code for the entire transaction for auth failures and developer system unavailability.
43        /// For individual device errors use the errorCode within the device object.
44        #[serde(skip_serializing_if = "Option::is_none")]
45        pub error_code: Option<String>,
46
47        /// Detailed error which will never be presented to users but may be logged or used during development.
48        #[serde(skip_serializing_if = "Option::is_none")]
49        pub debug_string: Option<String>,
50
51        /// Map of devices. Maps developer device ID to object of state properties.
52        pub devices: std::collections::HashMap<String, PayloadDevice>,
53    }
54
55    /// Device execution result.
56    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
57    #[serde(rename_all = "camelCase")]
58    pub struct PayloadDevice {
59        /// Result of the query operation.
60        pub status: PayloadDeviceStatus,
61
62        /// Expanding ERROR state if needed from the preset error codes, which will map to the errors presented to users.
63        pub error_code: Option<String>,
64
65        /// Device state
66        #[serde(default, flatten)]
67        pub state: State,
68    }
69
70    /// Device state.
71    #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
72    #[serde(rename_all = "camelCase")]
73    pub struct State {
74        // States common to all devices.
75        pub online: bool,
76
77        // States for OnOff trait.
78        #[serde(skip_serializing_if = "Option::is_none")]
79        pub on: Option<bool>,
80
81        // States for Brightness trait.
82        #[serde(skip_serializing_if = "Option::is_none")]
83        pub brightness: Option<u8>,
84
85        // States for ColorSetting trait.
86        #[serde(skip_serializing_if = "Option::is_none")]
87        pub color: Option<Color>,
88
89        // States for TemperatureSetting trait.
90        #[serde(skip_serializing_if = "Option::is_none")]
91        pub active_thermostat_mode: Option<String>,
92        #[serde(skip_serializing_if = "Option::is_none")]
93        pub target_temp_reached_estimate_unix_timestamp_sec: Option<u64>,
94        #[serde(skip_serializing_if = "Option::is_none")]
95        pub thermostat_humidity_ambient: Option<f64>,
96        #[serde(skip_serializing_if = "Option::is_none")]
97        pub thermostat_mode: Option<String>,
98        #[serde(skip_serializing_if = "Option::is_none")]
99        pub thermostat_temperature_ambient: Option<f64>,
100        #[serde(skip_serializing_if = "Option::is_none")]
101        pub thermostat_temperature_setpoint: Option<f64>,
102        #[serde(skip_serializing_if = "Option::is_none")]
103        pub thermostat_temperature_setpoint_high: Option<f64>,
104        #[serde(skip_serializing_if = "Option::is_none")]
105        pub thermostat_temperature_setpoint_low: Option<f64>,
106    }
107
108    #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
109    #[serde(rename_all = "camelCase")]
110    pub enum Color {
111        TemperatureK(u64),
112        SpectrumRgb(u32),
113        SpectrumHsv {
114            hue: f64,
115            saturation: f64,
116            value: f64,
117        },
118    }
119
120    /// Result of the query operation.
121    #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
122    #[repr(u8)]
123    #[serde(rename_all = "UPPERCASE")]
124    pub enum PayloadDeviceStatus {
125        /// Confirm that the query succeeded.
126        Success,
127
128        /// Target device is in offline state or unreachable.
129        Offline,
130
131        /// There is an issue or alert associated with a query.
132        /// The query could succeed or fail.
133        /// This status type is typically set when you want to send additional information about another connected device.
134        Exceptions,
135
136        /// Unable to query the target device.
137        Error,
138    }
139}