use constants for slave property indices

This commit is contained in:
LastExceed 2024-02-13 15:55:48 +01:00
parent ed4a89e3c0
commit 6acec2875e
4 changed files with 9 additions and 3 deletions

View File

@ -5,6 +5,7 @@ use std::collections::{HashMap, VecDeque};
use rumqttc::{AsyncClient, QoS}; use rumqttc::{AsyncClient, QoS};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use crate::utils::index;
use crate::utils::booking::Booking; use crate::utils::booking::Booking;
use crate::SLAVE_PROPERTIES; use crate::SLAVE_PROPERTIES;
@ -43,7 +44,7 @@ impl<Kind> State<Kind> {
//probably doesn't belong here, dunno where else to put it //probably doesn't belong here, dunno where else to put it
async fn update_power_state(&self, machine: &str, new_state: bool) { 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 = let topic =
if is_tasmota { if is_tasmota {
format!("cmnd/{machine}/Power") format!("cmnd/{machine}/Power")

View File

@ -7,6 +7,7 @@ use rumqttc::Event::Incoming;
use rumqttc::Packet::Publish; use rumqttc::Packet::Publish;
use crate::{State, Listener, BOOKING_TOPIC, SLAVES_BY_MASTER, SLAVE_PROPERTIES}; use crate::{State, Listener, BOOKING_TOPIC, SLAVES_BY_MASTER, SLAVE_PROPERTIES};
use crate::utils::index;
use crate::utils::get_power_state; use crate::utils::get_power_state;
use crate::utils::logs::{log_debug, machinelog}; use crate::utils::logs::{log_debug, machinelog};
use crate::utils::booking::Booking; use crate::utils::booking::Booking;
@ -146,10 +147,10 @@ impl State<Listener> {
.ok_or("unknown master")? .ok_or("unknown master")?
.sub(&slaves_used_by_others) .sub(&slaves_used_by_others)
.into_iter() .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 { 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); let shutdown_timestamp = Instant::now() + Duration::from_secs(30);
self.scheduled_shutdowns.write().await.push_back((shutdown_timestamp, slave)); self.scheduled_shutdowns.write().await.push_back((shutdown_timestamp, slave));
continue; continue;

View File

@ -5,6 +5,7 @@ use serde::de::DeserializeOwned;
pub mod logs; pub mod logs;
pub mod booking; pub mod booking;
pub mod index;
pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T { pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T {
let file_content = fs::read_to_string(path).expect("failed to read .toml file"); let file_content = fs::read_to_string(path).expect("failed to read .toml file");

3
src/utils/index.rs Normal file
View File

@ -0,0 +1,3 @@
pub const RUNS_CONTINUOUSLY: usize = 0;
pub const NEEDS_TRAILING_TIME: usize = 1;
pub const IS_TASMOTA: usize = 2;