feat!: Removed AddAdditionalMethods

It has been replaced with the add_methods device attribute.
This commit is contained in:
2025-09-09 04:24:20 +02:00
parent 23355190ca
commit 95a8a377e8
4 changed files with 31 additions and 53 deletions

View File

@@ -3,7 +3,6 @@ use std::convert::Infallible;
use async_trait::async_trait;
use automation_lib::device::{Device, LuaDeviceCreate};
use automation_lib::lua::traits::AddAdditionalMethods;
use automation_macro::{Device, LuaDeviceConfig};
use mlua::LuaSerdeExt;
use serde::{Deserialize, Serialize};
@@ -119,11 +118,26 @@ pub struct Config {
}
#[derive(Debug, Clone, Device)]
#[device(traits(AddAdditionalMethods))]
#[device(add_methods(Self::add_methods))]
pub struct Ntfy {
config: Config,
}
impl Ntfy {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
methods.add_async_method(
"send_notification",
async |lua, this, notification: mlua::Value| {
let notification: Notification = lua.from_value(notification)?;
this.send(notification).await;
Ok(())
},
);
}
}
#[async_trait]
impl LuaDeviceCreate for Ntfy {
type Config = Config;
@@ -162,21 +176,3 @@ impl Ntfy {
}
}
}
impl AddAdditionalMethods for Ntfy {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
where
Self: Sized + 'static,
{
methods.add_async_method(
"send_notification",
async |lua, this, notification: mlua::Value| {
let notification: Notification = lua.from_value(notification)?;
this.send(notification).await;
Ok(())
},
);
}
}