feat!: Removed AddAdditionalMethods
It has been replaced with the add_methods device attribute.
This commit is contained in:
@@ -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(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user