diff --git a/Cargo.lock b/Cargo.lock index fce38ad..59a7037 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,7 @@ dependencies = [ "rumqttc", "serde", "serde_json", + "serde_repr", "thiserror 2.0.16", "tokio", "tracing", @@ -143,18 +144,15 @@ version = "0.1.0" dependencies = [ "async-trait", "automation_cast", - "automation_macro", "bytes", "dyn-clone", "futures", "google_home", "indexmap", "mlua", - "reqwest", "rumqttc", "serde", "serde_json", - "serde_repr", "thiserror 2.0.16", "tokio", "tokio-cron-scheduler", diff --git a/automation_devices/Cargo.toml b/automation_devices/Cargo.toml index 3b80c03..9bebaa0 100644 --- a/automation_devices/Cargo.toml +++ b/automation_devices/Cargo.toml @@ -12,6 +12,7 @@ async-trait = { workspace = true } dyn-clone = { workspace = true } rumqttc = { workspace = true } tokio = { workspace = true } +serde_repr = { workspace = true } tracing = { workspace = true } serde_json = { workspace = true } serde = { workspace = true } diff --git a/automation_devices/src/contact_sensor.rs b/automation_devices/src/contact_sensor.rs index ebb8768..ce351a0 100644 --- a/automation_devices/src/contact_sensor.rs +++ b/automation_devices/src/contact_sensor.rs @@ -9,7 +9,6 @@ use automation_lib::error::DeviceConfigError; use automation_lib::event::{OnMqtt, OnPresence}; use automation_lib::messages::{ContactMessage, PresenceMessage}; use automation_lib::mqtt::WrappedAsyncClient; -use automation_lib::presence::DEFAULT_PRESENCE; use automation_macro::{LuaDevice, LuaDeviceConfig}; use google_home::device; use google_home::errors::{DeviceError, ErrorCode}; @@ -20,6 +19,8 @@ use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use tokio::task::JoinHandle; use tracing::{debug, error, trace, warn}; +use crate::presence::DEFAULT_PRESENCE; + #[derive(Debug, Clone, Deserialize, PartialEq, Eq, Copy)] pub enum SensorType { Door, diff --git a/automation_devices/src/lib.rs b/automation_devices/src/lib.rs index 238aacd..609493b 100644 --- a/automation_devices/src/lib.rs +++ b/automation_devices/src/lib.rs @@ -7,6 +7,8 @@ mod hue_switch; mod ikea_remote; mod kasa_outlet; mod light_sensor; +mod ntfy; +mod presence; mod wake_on_lan; mod washer; mod zigbee; @@ -24,6 +26,8 @@ pub use self::hue_switch::HueSwitch; pub use self::ikea_remote::IkeaRemote; pub use self::kasa_outlet::KasaOutlet; pub use self::light_sensor::LightSensor; +pub use self::ntfy::*; +pub use self::presence::Presence; pub use self::wake_on_lan::WakeOnLAN; pub use self::washer::Washer; @@ -35,11 +39,6 @@ macro_rules! register_device { } pub fn register_with_lua(lua: &mlua::Lua) -> mlua::Result<()> { - register_device!(lua, LightOnOff); - register_device!(lua, LightBrightness); - register_device!(lua, LightColorTemperature); - register_device!(lua, OutletOnOff); - register_device!(lua, OutletPower); register_device!(lua, AirFilter); register_device!(lua, ContactSensor); register_device!(lua, DebugBridge); @@ -48,7 +47,14 @@ pub fn register_with_lua(lua: &mlua::Lua) -> mlua::Result<()> { register_device!(lua, HueSwitch); register_device!(lua, IkeaRemote); register_device!(lua, KasaOutlet); + register_device!(lua, LightBrightness); + register_device!(lua, LightColorTemperature); + register_device!(lua, LightOnOff); register_device!(lua, LightSensor); + register_device!(lua, Ntfy); + register_device!(lua, OutletOnOff); + register_device!(lua, OutletPower); + register_device!(lua, Presence); register_device!(lua, WakeOnLAN); register_device!(lua, Washer); diff --git a/automation_lib/src/ntfy.rs b/automation_devices/src/ntfy.rs similarity index 95% rename from automation_lib/src/ntfy.rs rename to automation_devices/src/ntfy.rs index 24006e8..2fd7f96 100644 --- a/automation_lib/src/ntfy.rs +++ b/automation_devices/src/ntfy.rs @@ -2,16 +2,15 @@ use std::collections::HashMap; use std::convert::Infallible; use async_trait::async_trait; +use automation_lib::device::{Device, LuaDeviceCreate}; +use automation_lib::event::{self, EventChannel}; +use automation_lib::lua::traits::AddAdditionalMethods; use automation_macro::{LuaDevice, LuaDeviceConfig}; use mlua::LuaSerdeExt; use serde::{Deserialize, Serialize}; use serde_repr::*; use tracing::{error, trace, warn}; -use crate::device::{Device, LuaDeviceCreate}; -use crate::event::{self, EventChannel}; -use crate::lua::traits::AddAdditionalMethods; - #[derive(Debug, Serialize_repr, Deserialize, Clone, Copy)] #[repr(u8)] #[serde(rename_all = "snake_case")] @@ -123,7 +122,7 @@ pub struct Config { } #[derive(Debug, Clone, LuaDevice)] -#[traits(crate::lua::traits::AddAdditionalMethods)] +#[traits(AddAdditionalMethods)] pub struct Ntfy { config: Config, } diff --git a/automation_lib/src/presence.rs b/automation_devices/src/presence.rs similarity index 92% rename from automation_lib/src/presence.rs rename to automation_devices/src/presence.rs index 8a65535..491721e 100644 --- a/automation_lib/src/presence.rs +++ b/automation_devices/src/presence.rs @@ -2,18 +2,17 @@ use std::collections::HashMap; use std::sync::Arc; use async_trait::async_trait; +use automation_lib::action_callback::ActionCallback; +use automation_lib::config::MqttDeviceConfig; +use automation_lib::device::{Device, LuaDeviceCreate}; +use automation_lib::event::{self, Event, EventChannel, OnMqtt}; +use automation_lib::messages::PresenceMessage; +use automation_lib::mqtt::WrappedAsyncClient; use automation_macro::{LuaDevice, LuaDeviceConfig}; use rumqttc::Publish; use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use tracing::{debug, trace, warn}; -use crate::action_callback::ActionCallback; -use crate::config::MqttDeviceConfig; -use crate::device::{Device, LuaDeviceCreate}; -use crate::event::{self, Event, EventChannel, OnMqtt}; -use crate::messages::PresenceMessage; -use crate::mqtt::WrappedAsyncClient; - #[derive(Debug, Clone, LuaDeviceConfig)] pub struct Config { #[device_config(flatten)] diff --git a/automation_lib/Cargo.toml b/automation_lib/Cargo.toml index 039475e..a2aca78 100644 --- a/automation_lib/Cargo.toml +++ b/automation_lib/Cargo.toml @@ -4,15 +4,12 @@ version = "0.1.0" edition = "2024" [dependencies] -automation_macro = { workspace = true } automation_cast = { workspace = true } google_home = { workspace = true } rumqttc = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } -reqwest = { workspace = true } -serde_repr = { workspace = true } tracing = { workspace = true } bytes = { workspace = true } async-trait = { workspace = true } diff --git a/automation_lib/src/lib.rs b/automation_lib/src/lib.rs index 86434eb..4634704 100644 --- a/automation_lib/src/lib.rs +++ b/automation_lib/src/lib.rs @@ -10,6 +10,4 @@ pub mod helpers; pub mod lua; pub mod messages; pub mod mqtt; -pub mod ntfy; -pub mod presence; pub mod schedule; diff --git a/src/main.rs b/src/main.rs index 4169b15..6c01929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,6 @@ use automation_lib::config::{FulfillmentConfig, MqttConfig}; use automation_lib::device_manager::DeviceManager; use automation_lib::helpers; use automation_lib::mqtt::{self, WrappedAsyncClient}; -use automation_lib::ntfy::Ntfy; -use automation_lib::presence::Presence; use axum::extract::{FromRef, State}; use axum::http::StatusCode; use axum::routing::post; @@ -118,9 +116,6 @@ async fn app() -> anyhow::Result<()> { automation_devices::register_with_lua(&lua)?; helpers::register_with_lua(&lua)?; - lua.globals().set("Ntfy", lua.create_proxy::()?)?; - lua.globals() - .set("Presence", lua.create_proxy::()?)?; // TODO: Make this not hardcoded let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());