feat: WIP
This commit is contained in:
@@ -14,6 +14,7 @@ dyn-clone = { workspace = true }
|
||||
eui48 = { workspace = true }
|
||||
google_home = { workspace = true }
|
||||
inventory = { workspace = true }
|
||||
lua_typed = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
rumqttc = { workspace = true }
|
||||
|
||||
@@ -14,6 +14,7 @@ mod zigbee;
|
||||
|
||||
use automation_lib::Module;
|
||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||
use lua_typed::Typed;
|
||||
use tracing::debug;
|
||||
|
||||
macro_rules! register_device {
|
||||
@@ -64,3 +65,12 @@ pub fn create_module(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
|
||||
}
|
||||
|
||||
inventory::submit! {Module::new("devices", create_module)}
|
||||
|
||||
pub fn generate_definitions() {
|
||||
println!("{}", ntfy::Priority::generate_full().unwrap());
|
||||
println!("{}", ntfy::ActionType::generate_full().unwrap());
|
||||
println!("{}", ntfy::Action::generate_full().unwrap());
|
||||
println!("{}", ntfy::Notification::generate_full().unwrap());
|
||||
println!("{}", ntfy::Config::generate_full().unwrap());
|
||||
println!("{}", ntfy::Ntfy::generate_full().unwrap());
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ use std::convert::Infallible;
|
||||
use async_trait::async_trait;
|
||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||
use automation_macro::{Device, LuaDeviceConfig};
|
||||
use lua_typed::Typed;
|
||||
use mlua::LuaSerdeExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::*;
|
||||
use tracing::{error, trace, warn};
|
||||
|
||||
#[derive(Debug, Serialize_repr, Deserialize, Clone, Copy)]
|
||||
#[derive(Debug, Serialize_repr, Deserialize, Clone, Copy, Typed)]
|
||||
#[repr(u8)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Priority {
|
||||
@@ -20,7 +21,7 @@ pub enum Priority {
|
||||
Max,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Typed)]
|
||||
#[serde(rename_all = "snake_case", tag = "action")]
|
||||
pub enum ActionType {
|
||||
Broadcast {
|
||||
@@ -31,7 +32,7 @@ pub enum ActionType {
|
||||
// Http
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Typed)]
|
||||
pub struct Action {
|
||||
#[serde(flatten)]
|
||||
pub action: ActionType,
|
||||
@@ -39,14 +40,14 @@ pub struct Action {
|
||||
pub clear: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Typed)]
|
||||
struct NotificationFinal {
|
||||
topic: String,
|
||||
#[serde(flatten)]
|
||||
inner: Notification,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Clone, Deserialize)]
|
||||
#[derive(Debug, Serialize, Clone, Deserialize, Typed)]
|
||||
pub struct Notification {
|
||||
title: String,
|
||||
message: Option<String>,
|
||||
@@ -67,7 +68,7 @@ impl Notification {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, LuaDeviceConfig)]
|
||||
#[derive(Debug, Clone, LuaDeviceConfig, Typed)]
|
||||
pub struct Config {
|
||||
#[device_config(default("https://ntfy.sh".into()))]
|
||||
pub url: String,
|
||||
@@ -96,6 +97,21 @@ impl Ntfy {
|
||||
}
|
||||
}
|
||||
|
||||
impl Typed for Ntfy {
|
||||
fn type_name() -> String {
|
||||
"Ntfy".into()
|
||||
}
|
||||
|
||||
fn generate_header() -> Option<String> {
|
||||
Some("---@class Ntfy\n".into())
|
||||
}
|
||||
|
||||
fn generate_members() -> Option<String> {
|
||||
Some("---@async\n---@param notification Notification\nfunction Ntfy:send_notification(notification) end".into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl LuaDeviceCreate for Ntfy {
|
||||
type Config = Config;
|
||||
|
||||
Reference in New Issue
Block a user