Moved schedule config from yml to lua
This commit is contained in:
parent
68b9676616
commit
e43bd4ea2a
16
config.lua
16
config.lua
|
@ -158,7 +158,7 @@ automation.device_manager:create(
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
automation.device_manager:create(
|
local bedroom_air_filter = automation.device_manager:create(
|
||||||
"bedroom_air_filter",
|
"bedroom_air_filter",
|
||||||
AirFilter.new({
|
AirFilter.new({
|
||||||
name = "Air Filter",
|
name = "Air Filter",
|
||||||
|
@ -167,3 +167,17 @@ automation.device_manager:create(
|
||||||
client = automation.mqtt_client,
|
client = automation.mqtt_client,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- TODO: Use the wrapped device bedroom_air_filter instead of the string
|
||||||
|
automation.device_manager:add_schedule({
|
||||||
|
["0 0 19 * * *"] = {
|
||||||
|
on = {
|
||||||
|
"bedroom_air_filter",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
["0 0 20 * * *"] = {
|
||||||
|
off = {
|
||||||
|
"bedroom_air_filter",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
|
@ -13,13 +13,3 @@ ntfy:
|
||||||
|
|
||||||
presence:
|
presence:
|
||||||
topic: "automation/presence/+/#"
|
topic: "automation/presence/+/#"
|
||||||
|
|
||||||
# Run the air filter everyday for 19:00 to 20:00
|
|
||||||
schedule:
|
|
||||||
0 0 19 * * *:
|
|
||||||
on:
|
|
||||||
- "bedroom_air_filter"
|
|
||||||
|
|
||||||
0 0 20 * * *:
|
|
||||||
off:
|
|
||||||
- "bedroom_air_filter"
|
|
||||||
|
|
|
@ -14,12 +14,3 @@ ntfy:
|
||||||
|
|
||||||
presence:
|
presence:
|
||||||
topic: "automation_dev/presence/+/#"
|
topic: "automation_dev/presence/+/#"
|
||||||
|
|
||||||
schedule:
|
|
||||||
# 0/30 * * * * *:
|
|
||||||
# on:
|
|
||||||
# - *outlet
|
|
||||||
#
|
|
||||||
# 15/30 * * * * *:
|
|
||||||
# off:
|
|
||||||
# - *outlet
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ use tracing::debug;
|
||||||
use crate::auth::OpenIDConfig;
|
use crate::auth::OpenIDConfig;
|
||||||
use crate::devices::PresenceConfig;
|
use crate::devices::PresenceConfig;
|
||||||
use crate::error::{ConfigParseError, MissingEnv};
|
use crate::error::{ConfigParseError, MissingEnv};
|
||||||
use crate::schedule::Schedule;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -21,7 +20,6 @@ pub struct Config {
|
||||||
pub fullfillment: FullfillmentConfig,
|
pub fullfillment: FullfillmentConfig,
|
||||||
pub ntfy: Option<NtfyConfig>,
|
pub ntfy: Option<NtfyConfig>,
|
||||||
pub presence: PresenceConfig,
|
pub presence: PresenceConfig,
|
||||||
pub schedule: Schedule,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
|
|
@ -6,7 +6,7 @@ use async_trait::async_trait;
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use google_home::traits::OnOff;
|
use google_home::traits::OnOff;
|
||||||
use mlua::FromLua;
|
use mlua::{FromLua, LuaSerdeExt};
|
||||||
use rumqttc::{matches, AsyncClient, QoS};
|
use rumqttc::{matches, AsyncClient, QoS};
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
use tokio_cron_scheduler::{Job, JobScheduler};
|
use tokio_cron_scheduler::{Job, JobScheduler};
|
||||||
|
@ -261,6 +261,12 @@ impl mlua::UserData for DeviceManager {
|
||||||
|
|
||||||
Ok(this.add(device).await)
|
Ok(this.add(device).await)
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
|
methods.add_async_method("add_schedule", |lua, this, schedule| async {
|
||||||
|
let schedule = lua.from_value(schedule)?;
|
||||||
|
this.add_schedule(schedule).await;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,6 @@ async fn app() -> anyhow::Result<()> {
|
||||||
// Setup the device handler
|
// Setup the device handler
|
||||||
let device_manager = DeviceManager::new(client.clone());
|
let device_manager = DeviceManager::new(client.clone());
|
||||||
|
|
||||||
device_manager.add_schedule(config.schedule).await;
|
|
||||||
|
|
||||||
let event_channel = device_manager.event_channel();
|
let event_channel = device_manager.event_channel();
|
||||||
|
|
||||||
// Create and add the presence system
|
// Create and add the presence system
|
||||||
|
|
Loading…
Reference in New Issue
Block a user