refactor: Move module load code into separate function
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -100,7 +100,6 @@ dependencies = [
|
|||||||
"git-version",
|
"git-version",
|
||||||
"google_home",
|
"google_home",
|
||||||
"hostname",
|
"hostname",
|
||||||
"inventory",
|
|
||||||
"mlua",
|
"mlua",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rumqttc",
|
"rumqttc",
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ dotenvy = { workspace = true }
|
|||||||
git-version = "0.3.9"
|
git-version = "0.3.9"
|
||||||
google_home = { workspace = true }
|
google_home = { workspace = true }
|
||||||
hostname = { workspace = true }
|
hostname = { workspace = true }
|
||||||
inventory = { workspace = true }
|
|
||||||
mlua = { workspace = true }
|
mlua = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
rumqttc = { workspace = true }
|
rumqttc = { workspace = true }
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
|
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
pub mod action_callback;
|
pub mod action_callback;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod device;
|
pub mod device;
|
||||||
@@ -34,4 +36,15 @@ impl Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_modules(lua: &mlua::Lua) -> mlua::Result<()> {
|
||||||
|
debug!("Loading modules...");
|
||||||
|
for module in inventory::iter::<Module> {
|
||||||
|
debug!(name = module.get_name(), "Registering");
|
||||||
|
let table = module.register(lua)?;
|
||||||
|
lua.register_module(module.get_name(), table)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
inventory::collect!(Module);
|
inventory::collect!(Module);
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
|||||||
use ::config::{Environment, File};
|
use ::config::{Environment, File};
|
||||||
use automation_lib::config::{FulfillmentConfig, MqttConfig};
|
use automation_lib::config::{FulfillmentConfig, MqttConfig};
|
||||||
use automation_lib::device_manager::DeviceManager;
|
use automation_lib::device_manager::DeviceManager;
|
||||||
|
use automation_lib::helpers;
|
||||||
use automation_lib::mqtt::{self, WrappedAsyncClient};
|
use automation_lib::mqtt::{self, WrappedAsyncClient};
|
||||||
use automation_lib::{Module, helpers};
|
|
||||||
use axum::extract::{FromRef, State};
|
use axum::extract::{FromRef, State};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
@@ -141,12 +141,7 @@ async fn app() -> anyhow::Result<()> {
|
|||||||
})?;
|
})?;
|
||||||
lua.globals().set("print", print)?;
|
lua.globals().set("print", print)?;
|
||||||
|
|
||||||
debug!("Loading modules...");
|
automation_lib::load_modules(&lua)?;
|
||||||
for module in inventory::iter::<Module> {
|
|
||||||
debug!(name = module.get_name(), "Registering");
|
|
||||||
let table = module.register(&lua)?;
|
|
||||||
lua.register_module(module.get_name(), table)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mqtt = lua.create_table()?;
|
let mqtt = lua.create_table()?;
|
||||||
let event_channel = device_manager.event_channel();
|
let event_channel = device_manager.event_channel();
|
||||||
|
|||||||
Reference in New Issue
Block a user