Move ntfy and presence to automation_devices
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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)]
|
||||
@@ -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 }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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::<Ntfy>()?)?;
|
||||
lua.globals()
|
||||
.set("Presence", lua.create_proxy::<Presence>()?)?;
|
||||
|
||||
// TODO: Make this not hardcoded
|
||||
let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());
|
||||
|
||||
Reference in New Issue
Block a user