mirror of
https://github.com/LastExceed/spacermake.git
synced 2025-03-12 06:51:43 +01:00
use constants for slave property indices
This commit is contained in:
parent
ed4a89e3c0
commit
6acec2875e
@ -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<Kind> State<Kind> {
|
||||
|
||||
//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")
|
||||
|
@ -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<Listener> {
|
||||
.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;
|
||||
|
@ -5,6 +5,7 @@ use serde::de::DeserializeOwned;
|
||||
|
||||
pub mod logs;
|
||||
pub mod booking;
|
||||
pub mod index;
|
||||
|
||||
pub fn parse_toml_file<T: DeserializeOwned>(path: &str) -> T {
|
||||
let file_content = fs::read_to_string(path).expect("failed to read .toml file");
|
||||
|
3
src/utils/index.rs
Normal file
3
src/utils/index.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub const RUNS_CONTINUOUSLY: usize = 0;
|
||||
pub const NEEDS_TRAILING_TIME: usize = 1;
|
||||
pub const IS_TASMOTA: usize = 2;
|
Loading…
x
Reference in New Issue
Block a user