Fixed fan speed control in google home
All checks were successful
Build and deploy automation_rs / Run pre-commit checks (push) Successful in 4m28s
Build and deploy automation_rs / Build automation_rs (push) Successful in 4m43s
Build and deploy automation_rs / Build Docker image (push) Successful in 54s
Build and deploy automation_rs / Deploy Docker container (push) Successful in 30s

This commit is contained in:
Dreaded_X 2024-05-26 02:12:13 +02:00
parent d8d348d906
commit 32aa981e31
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4

View File

@ -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#"{