diff --git a/src/state.rs b/src/state.rs index 0bae898..3e7479e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,6 +5,7 @@ use std::collections::{HashMap, VecDeque}; use rumqttc::{AsyncClient, QoS}; use tokio::sync::RwLock; +use crate::utils::index; use crate::utils::booking::Booking; use crate::SLAVE_PROPERTIES; @@ -43,7 +44,7 @@ impl State { //probably doesn't belong here, dunno where else to put it async fn update_power_state(&self, machine: &str, new_state: bool) { - let is_tasmota = SLAVE_PROPERTIES[machine][2]; + let is_tasmota = SLAVE_PROPERTIES[machine][index::IS_TASMOTA]; let topic = if is_tasmota { format!("cmnd/{machine}/Power") diff --git a/src/state/listener.rs b/src/state/listener.rs index 172170c..9cf3f8a 100644 --- a/src/state/listener.rs +++ b/src/state/listener.rs @@ -7,6 +7,7 @@ use rumqttc::Event::Incoming; use rumqttc::Packet::Publish; use crate::{State, Listener, BOOKING_TOPIC, SLAVES_BY_MASTER, SLAVE_PROPERTIES}; +use crate::utils::index; use crate::utils::get_power_state; use crate::utils::logs::{log_debug, machinelog}; use crate::utils::booking::Booking; @@ -146,10 +147,10 @@ impl State { .ok_or("unknown master")? .sub(&slaves_used_by_others) .into_iter() - .filter(|slave| if SLAVE_PROPERTIES[slave][0] { long_slaves } else { short_slaves }); + .filter(|slave| if SLAVE_PROPERTIES[slave][index::RUNS_CONTINUOUSLY] { long_slaves } else { short_slaves }); for slave in slaves_to_update { - if !power && SLAVE_PROPERTIES[&slave][1] { + if !power && SLAVE_PROPERTIES[&slave][index::NEEDS_TRAILING_TIME] { let shutdown_timestamp = Instant::now() + Duration::from_secs(30); self.scheduled_shutdowns.write().await.push_back((shutdown_timestamp, slave)); continue; diff --git a/src/utils.rs b/src/utils.rs index b13f7d6..d676686 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,6 +5,7 @@ use serde::de::DeserializeOwned; pub mod logs; pub mod booking; +pub mod index; pub fn parse_toml_file(path: &str) -> T { let file_content = fs::read_to_string(path).expect("failed to read .toml file"); diff --git a/src/utils/index.rs b/src/utils/index.rs new file mode 100644 index 0000000..03766d5 --- /dev/null +++ b/src/utils/index.rs @@ -0,0 +1,3 @@ +pub const RUNS_CONTINUOUSLY: usize = 0; +pub const NEEDS_TRAILING_TIME: usize = 1; +pub const IS_TASMOTA: usize = 2; \ No newline at end of file