Added color temperature support with ColorSetting

This commit is contained in:
2025-08-22 03:06:30 +02:00
parent e27412339c
commit fe83568839
2 changed files with 41 additions and 1 deletions

View File

@@ -96,6 +96,26 @@ macro_rules! impl_device {
}); });
} }
if impls::impls!($device: google_home::traits::ColorSetting) {
methods.add_async_method("set_color_temperature", |_lua, this, temperature: u32| async move {
(this.deref().cast() as Option<&dyn google_home::traits::ColorSetting>)
.expect("Cast should be valid")
.set_color(google_home::traits::Color {temperature})
.await
.unwrap();
Ok(())
});
methods.add_async_method("color_temperature", |_lua, this, _: ()| async move {
Ok((this.deref().cast() as Option<&dyn google_home::traits::ColorSetting>)
.expect("Cast should be valid")
.color()
.await
.temperature)
});
}
if impls::impls!($device: google_home::traits::OpenClose) { if impls::impls!($device: google_home::traits::OpenClose) {
// TODO: Make discrete_only_open_close and query_only_open_close static, that way we can // TODO: Make discrete_only_open_close and query_only_open_close static, that way we can
// add only the supported functions and drop _percet if discrete is true // add only the supported functions and drop _percet if discrete is true

View File

@@ -1,7 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use automation_cast::Cast; use automation_cast::Cast;
use google_home_macro::traits; use google_home_macro::traits;
use serde::Serialize; use serde::{Deserialize, Serialize};
use crate::errors::ErrorCode; use crate::errors::ErrorCode;
use crate::Device; use crate::Device;
@@ -26,6 +26,12 @@ traits! {
async fn brightness(&self) -> Result<u8, ErrorCode>, async fn brightness(&self) -> Result<u8, ErrorCode>,
"action.devices.commands.BrightnessAbsolute" => async fn set_brightness(&self, brightness: u8) -> Result<(), ErrorCode>, "action.devices.commands.BrightnessAbsolute" => async fn set_brightness(&self, brightness: u8) -> Result<(), ErrorCode>,
}, },
"action.devices.traits.ColorSetting" => trait ColorSetting {
color_temperature_range: ColorTemperatureRange,
async fn color(&self) -> Color,
"action.devices.commands.ColorAbsolute" => async fn set_color(&self, color: Color) -> Result<(), ErrorCode>,
},
"action.devices.traits.Scene" => trait Scene { "action.devices.traits.Scene" => trait Scene {
scene_reversible: Option<bool>, scene_reversible: Option<bool>,
@@ -56,6 +62,20 @@ traits! {
} }
} }
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ColorTemperatureRange {
pub temperature_min_k: u32,
pub temperature_max_k: u32,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Color {
#[serde(rename(serialize = "temperatureK"))]
pub temperature: u32,
}
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct SpeedValue { pub struct SpeedValue {
pub speed_synonym: Vec<String>, pub speed_synonym: Vec<String>,