chore: 📎 + fmt
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
use crate::hal::Moistures;
|
||||
use crate::{
|
||||
config::PlantConfig,
|
||||
hal::HAL,
|
||||
in_time_range,
|
||||
};
|
||||
use crate::{config::PlantConfig, hal::HAL, in_time_range};
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -76,7 +72,7 @@ impl PumpState {
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
|
||||
pub enum PlantWateringMode {
|
||||
OFF,
|
||||
Off,
|
||||
TargetMoisture,
|
||||
MinMoisture,
|
||||
TimerOnly,
|
||||
@@ -115,20 +111,24 @@ fn map_range_moisture(
|
||||
}
|
||||
|
||||
impl PlantState {
|
||||
pub async fn read_hardware_state(moistures: Moistures, plant_id: usize, board: &mut HAL<'_>) -> Self {
|
||||
pub async fn read_hardware_state(
|
||||
moistures: Moistures,
|
||||
plant_id: usize,
|
||||
board: &mut HAL<'_>,
|
||||
) -> Self {
|
||||
let sensor_a = if board.board_hal.get_config().plants[plant_id].sensor_a {
|
||||
let raw = moistures.sensor_a_hz[plant_id];
|
||||
match map_range_moisture(
|
||||
raw,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency,
|
||||
) {
|
||||
Ok(moisture_percent) => MoistureSensorState::MoistureValue {
|
||||
raw_hz: raw,
|
||||
moisture_percent,
|
||||
},
|
||||
Err(err) => MoistureSensorState::SensorError(err),
|
||||
}
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency,
|
||||
) {
|
||||
Ok(moisture_percent) => MoistureSensorState::MoistureValue {
|
||||
raw_hz: raw,
|
||||
moisture_percent,
|
||||
},
|
||||
Err(err) => MoistureSensorState::SensorError(err),
|
||||
}
|
||||
} else {
|
||||
MoistureSensorState::Disabled
|
||||
};
|
||||
@@ -161,13 +161,13 @@ impl PlantState {
|
||||
},
|
||||
};
|
||||
if state.is_err() {
|
||||
let _ = board.board_hal.fault(plant_id, true);
|
||||
let _ = board.board_hal.fault(plant_id, true).await;
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
pub fn pump_in_timeout(&self, plant_conf: &PlantConfig, current_time: &DateTime<Tz>) -> bool {
|
||||
if matches!(plant_conf.mode, PlantWateringMode::OFF) {
|
||||
if matches!(plant_conf.mode, PlantWateringMode::Off) {
|
||||
return false;
|
||||
}
|
||||
self.pump.previous_pump.is_some_and(|last_pump| {
|
||||
@@ -208,7 +208,7 @@ impl PlantState {
|
||||
current_time: &DateTime<Tz>,
|
||||
) -> bool {
|
||||
match plant_conf.mode {
|
||||
PlantWateringMode::OFF => false,
|
||||
PlantWateringMode::Off => false,
|
||||
PlantWateringMode::TargetMoisture => {
|
||||
let (moisture_percent, _) = self.plant_moisture();
|
||||
if let Some(moisture_percent) = moisture_percent {
|
||||
@@ -229,28 +229,8 @@ impl PlantState {
|
||||
}
|
||||
}
|
||||
PlantWateringMode::MinMoisture => {
|
||||
let (moisture_percent, _) = self.plant_moisture();
|
||||
if let Some(_moisture_percent) = moisture_percent {
|
||||
if self.pump_in_timeout(plant_conf, current_time) {
|
||||
false
|
||||
} else if !in_time_range(
|
||||
current_time,
|
||||
plant_conf.pump_hour_start,
|
||||
plant_conf.pump_hour_end,
|
||||
) {
|
||||
false
|
||||
} else if true {
|
||||
//if not cooldown min and below max
|
||||
true
|
||||
} else if true {
|
||||
//if below min disable cooldown min
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
// TODO
|
||||
false
|
||||
}
|
||||
PlantWateringMode::TimerOnly => !self.pump_in_timeout(plant_conf, current_time),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user