diff --git a/google-home/src/request/execute.rs b/google-home/src/request/execute.rs index 0d67bcf..b3a640a 100644 --- a/google-home/src/request/execute.rs +++ b/google-home/src/request/execute.rs @@ -27,7 +27,10 @@ pub enum CommandType { OnOff { on: bool }, #[serde(rename = "action.devices.commands.ActivateScene")] ActivateScene { deactivate: bool }, - #[serde(rename = "action.devices.commands.SetFanSpeed")] + #[serde( + rename = "action.devices.commands.SetFanSpeed", + rename_all = "camelCase" + )] SetFanSpeed { fan_speed: String }, } @@ -36,6 +39,49 @@ mod tests { use super::*; use crate::request::{Intent, Request}; + #[test] + fn deserialize_set_fan_speed() { + let json = r#"{ + "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", + "inputs": [ + { + "intent": "action.devices.EXECUTE", + "payload": { + "commands": [ + { + "devices": [], + "execution": [ + { + "command": "action.devices.commands.SetFanSpeed", + "params": { + "fanSpeed": "Test" + } + } + ] + } + ] + } + } + ] +}"#; + + let req: Request = serde_json::from_str(json).unwrap(); + + assert_eq!(req.inputs.len(), 1); + match &req.inputs[0] { + Intent::Execute(payload) => { + assert_eq!(payload.commands.len(), 1); + assert_eq!(payload.commands[0].devices.len(), 0); + assert_eq!(payload.commands[0].execution.len(), 1); + match &payload.commands[0].execution[0] { + CommandType::SetFanSpeed { fan_speed } => assert_eq!(fan_speed, "Test"), + _ => panic!("Expected SetFanSpeed"), + } + } + _ => panic!("Expected Execute intent"), + }; + } + #[test] fn deserialize() { let json = r#"{