use proper error handling
This commit is contained in:
parent
48b0777d94
commit
b993f2b037
@ -611,7 +611,7 @@ fn determine_state_target_moisture_for_plant(
|
|||||||
plant: usize,
|
plant: usize,
|
||||||
state: &mut PlantState,
|
state: &mut PlantState,
|
||||||
config: &PlantControllerConfig,
|
config: &PlantControllerConfig,
|
||||||
tank_state: &TankInfo,
|
tank_state: &TankState,
|
||||||
cur: DateTime<Tz>,
|
cur: DateTime<Tz>,
|
||||||
) {
|
) {
|
||||||
let plant_config = &config.plants[plant];
|
let plant_config = &config.plants[plant];
|
||||||
@ -657,10 +657,17 @@ fn determine_state_target_moisture_for_plant(
|
|||||||
|
|
||||||
if a_low || b_low {
|
if a_low || b_low {
|
||||||
state.dry = true;
|
state.dry = true;
|
||||||
if tank_state.sensor_error && !config.tank.tank_allow_pumping_if_sensor_error {
|
match tank_state.enough_water(&config.tank) {
|
||||||
//ignore is ok
|
Err(_tank_err) => {
|
||||||
} else if !tank_state.enough_water {
|
if !config.tank.tank_allow_pumping_if_sensor_error {
|
||||||
state.no_water = true;
|
// ignore is ok
|
||||||
|
// wtf does this meen, shouldn't something happen if the configuration specifies
|
||||||
|
// that no water should flow if there was an error?
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(enough_water) => {
|
||||||
|
state.no_water = !enough_water
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||||
@ -701,7 +708,7 @@ fn determine_state_timer_only_for_plant(
|
|||||||
plant: usize,
|
plant: usize,
|
||||||
state: &mut PlantState,
|
state: &mut PlantState,
|
||||||
config: &PlantControllerConfig,
|
config: &PlantControllerConfig,
|
||||||
tank_state: &TankInfo,
|
tank_state: &TankState,
|
||||||
cur: DateTime<Tz>,
|
cur: DateTime<Tz>,
|
||||||
) {
|
) {
|
||||||
let plant_config = &config.plants[plant];
|
let plant_config = &config.plants[plant];
|
||||||
@ -716,10 +723,15 @@ fn determine_state_timer_only_for_plant(
|
|||||||
state.next_pump = Some(europe_time);
|
state.next_pump = Some(europe_time);
|
||||||
state.cooldown = true;
|
state.cooldown = true;
|
||||||
} else {
|
} else {
|
||||||
if tank_state.sensor_error && !config.tank.tank_allow_pumping_if_sensor_error {
|
match tank_state.enough_water(&config.tank) {
|
||||||
state.do_water = true;
|
Err(_tank_err) => {
|
||||||
} else if !tank_state.enough_water {
|
if !config.tank.tank_allow_pumping_if_sensor_error {
|
||||||
state.no_water = true;
|
state.do_water = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(enough_water) => {
|
||||||
|
state.no_water = !enough_water;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -739,7 +751,7 @@ fn determine_state_timer_and_deadzone_for_plant(
|
|||||||
plant: usize,
|
plant: usize,
|
||||||
state: &mut PlantState,
|
state: &mut PlantState,
|
||||||
config: &PlantControllerConfig,
|
config: &PlantControllerConfig,
|
||||||
tank_state: &TankInfo,
|
tank_state: &TankState,
|
||||||
cur: DateTime<Tz>,
|
cur: DateTime<Tz>,
|
||||||
) {
|
) {
|
||||||
let plant_config = &config.plants[plant];
|
let plant_config = &config.plants[plant];
|
||||||
@ -762,10 +774,15 @@ fn determine_state_timer_and_deadzone_for_plant(
|
|||||||
state.out_of_work_hour = true;
|
state.out_of_work_hour = true;
|
||||||
}
|
}
|
||||||
if !state.cooldown && !state.out_of_work_hour {
|
if !state.cooldown && !state.out_of_work_hour {
|
||||||
if tank_state.sensor_error && !config.tank.tank_allow_pumping_if_sensor_error {
|
match tank_state.enough_water(&config.tank) {
|
||||||
state.do_water = true;
|
Err(_tank_err) => {
|
||||||
} else if !tank_state.enough_water {
|
if !config.tank.tank_allow_pumping_if_sensor_error {
|
||||||
state.no_water = true;
|
state.do_water = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(enough_water) => {
|
||||||
|
state.no_water = !enough_water;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -783,7 +800,7 @@ fn determine_state_timer_and_deadzone_for_plant(
|
|||||||
fn determine_plant_state(
|
fn determine_plant_state(
|
||||||
plantstate: &mut [PlantState; PLANT_COUNT],
|
plantstate: &mut [PlantState; PLANT_COUNT],
|
||||||
cur: DateTime<Tz>,
|
cur: DateTime<Tz>,
|
||||||
tank_state: &TankInfo,
|
tank_state: &TankState,
|
||||||
config: &PlantControllerConfig,
|
config: &PlantControllerConfig,
|
||||||
board: &mut std::sync::MutexGuard<'_, PlantCtrlBoard<'_>>,
|
board: &mut std::sync::MutexGuard<'_, PlantCtrlBoard<'_>>,
|
||||||
) {
|
) {
|
||||||
|
@ -123,6 +123,12 @@ impl TankState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn got_error(&self, config: &TankConfig) -> Option<TankError> {
|
||||||
|
match self {
|
||||||
|
TankState::TankSensorPresent(raw_value_mv) => raw_voltage_to_tank_fill_percent(*raw_value_mv, config).err(),
|
||||||
|
TankState::TankSensorDisabled => Some(TankError::SensorDisabled),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user