automation_rs/google-home/src/bin/expand.rs
Dreaded_X 54fa9f3b66
Some checks failed
Build and deploy automation_rs / Run pre-commit checks (push) Failing after 4m28s
Build and deploy automation_rs / Build automation_rs (push) Successful in 4m48s
Build and deploy automation_rs / Build Docker image (push) Successful in 55s
Build and deploy automation_rs / Deploy Docker container (push) Has been skipped
WIP: Working on trait macro
2024-05-31 23:53:38 +02:00

64 lines
1.8 KiB
Rust

use automation_cast::Cast;
use automation_macro::google_home_traits;
use google_home::errors::ErrorCode;
use google_home::traits::AvailableSpeeds;
google_home_traits! {
GoogleHomeDevice {
"action.devices.traits.OnOff" => trait OnOff {
command_only_on_off: bool,
// This one is optional
query_only_on_off: Option<bool>,
async fn is_on(&self) -> Result<bool, ErrorCode> => on,
"action.devices.commands.OnOff" => async fn set_on(&self, on: bool) -> Result<(), ErrorCode>,
},
"action.devices.traits.Scene" => trait Scene {
scene_reversible: Option<bool>,
"action.devices.commands.ActivateScene" => async fn set_active(&self, activate: bool) -> Result<(), ErrorCode>,
},
"action.devices.traits.FanSpeed" => trait FanSpeed {
reversible: Option<bool>,
command_only_fan_speed: Option<bool>,
available_fan_speeds: AvailableSpeeds,
fn get_fan_speed(&self) -> Result<String, ErrorCode> => current_fan_speed_setting,
"action.devices.commands.SetFanSpeed" => fn set_speed(&self, fan_speed: String),
},
"action.devices.traits.HumiditySetting" => trait HumiditySetting {
query_only_humidity_setting: Option<bool>,
fn get_humidity(&self) -> Result<isize, ErrorCode> => humidity_ambient_percent,
}
}
}
trait Casts:
Cast<dyn OnOff> + Cast<dyn Scene> + Cast<dyn FanSpeed> + Cast<dyn HumiditySetting>
{
}
trait GoogleHomeDevice: Casts {}
struct Device {}
#[async_trait::async_trait]
impl OnOff for Device {
fn command_only_on_off(&self) -> bool {
false
}
async fn is_on(&self) -> Result<bool, ErrorCode> {
Ok(true)
}
async fn set_on(&self, _on: bool) -> Result<(), ErrorCode> {
Ok(())
}
}
fn main() {}