WIP
All checks were successful
Build and deploy / build (push) Successful in 11m20s
Build and deploy / Deploy container (push) Has been skipped

This commit is contained in:
2025-09-18 01:45:31 +02:00
parent 06b3154733
commit df45d4c489
14 changed files with 464 additions and 36 deletions

View File

@@ -1,11 +1,16 @@
use std::marker::PhantomData;
use std::ops::Deref;
// TODO: Enable and disable functions based on query_only and command_only
pub trait OnOff {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
pub struct OnOff<T: google_home::traits::OnOff> {
_phantom: PhantomData<T>,
}
impl<T: google_home::traits::OnOff> OnOff<T> {
pub fn add_methods<M: mlua::UserDataMethods<T>>(methods: &mut M)
where
Self: Sized + google_home::traits::OnOff + 'static,
T: Sized + google_home::traits::OnOff + 'static,
{
methods.add_async_method("set_on", async |_lua, this, on: bool| {
this.deref().set_on(on).await.unwrap();
@@ -17,13 +22,25 @@ pub trait OnOff {
Ok(this.deref().on().await.unwrap())
});
}
}
impl<T> OnOff for T where T: google_home::traits::OnOff {}
pub trait Brightness {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
pub fn generate_definitions(name: &str) -> String {
let mut output = String::new();
output += &format!("---@async\n---@param on boolean\nfunction {name}:set_on(on) end\n");
output += &format!("---@async\n---@return boolean\nfunction {name}:on() end\n");
output
}
}
pub struct Brightness<T: google_home::traits::Brightness> {
_phantom: PhantomData<T>,
}
impl<T: google_home::traits::Brightness> Brightness<T> {
pub fn add_methods<M: mlua::UserDataMethods<T>>(methods: &mut M)
where
Self: Sized + google_home::traits::Brightness + 'static,
T: Sized + google_home::traits::Brightness + 'static,
{
methods.add_async_method("set_brightness", async |_lua, this, brightness: u8| {
this.set_brightness(brightness).await.unwrap();
@@ -35,13 +52,27 @@ pub trait Brightness {
Ok(this.brightness().await.unwrap())
});
}
}
impl<T> Brightness for T where T: google_home::traits::Brightness {}
pub trait ColorSetting {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
pub fn generate_definitions(name: &str) -> String {
let mut output = String::new();
output += &format!(
"---@async\n---@param brightness integer\nfunction {name}:set_brightness(brightness) end\n"
);
output += &format!("---@async\n---@return integer\nfunction {name}:brightness() end\n");
output
}
}
pub struct ColorSetting<T: google_home::traits::ColorSetting> {
_phantom: PhantomData<T>,
}
impl<T: google_home::traits::ColorSetting> ColorSetting<T> {
pub fn add_methods<M: mlua::UserDataMethods<T>>(methods: &mut M)
where
Self: Sized + google_home::traits::ColorSetting + 'static,
T: Sized + google_home::traits::ColorSetting + 'static,
{
methods.add_async_method(
"set_color_temperature",
@@ -58,13 +89,28 @@ pub trait ColorSetting {
Ok(this.color().await.temperature)
});
}
}
impl<T> ColorSetting for T where T: google_home::traits::ColorSetting {}
pub trait OpenClose {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
pub fn generate_definitions(name: &str) -> String {
let mut output = String::new();
output += &format!(
"---@async\n---@param temperature integer\nfunction {name}:set_color_temperature(temperature) end\n"
);
output +=
&format!("---@async\n---@return integer\nfunction {name}:color_temperature() end\n");
output
}
}
pub struct OpenClose<T: google_home::traits::OpenClose> {
_phantom: PhantomData<T>,
}
impl<T: google_home::traits::OpenClose> OpenClose<T> {
pub fn add_methods<M: mlua::UserDataMethods<T>>(methods: &mut M)
where
Self: Sized + google_home::traits::OpenClose + 'static,
T: Sized + google_home::traits::OpenClose + 'static,
{
methods.add_async_method("set_open_percent", async |_lua, this, open_percent: u8| {
this.set_open_percent(open_percent).await.unwrap();
@@ -76,5 +122,16 @@ pub trait OpenClose {
Ok(this.open_percent().await.unwrap())
});
}
pub fn generate_definitions(type_name: &str) -> String {
let mut output = String::new();
output += &format!(
"---@async\n---@param open_percent integer\nfunction {type_name}:set_open_percent(open_percent) end\n"
);
output +=
&format!("---@async\n---@return integer\nfunction {type_name}:open_percent() end\n");
output
}
}
impl<T> OpenClose for T where T: google_home::traits::OpenClose {}