also add percent to tank mqtt
This commit is contained in:
parent
9509be9527
commit
110cb50098
@ -86,16 +86,21 @@ impl TankState {
|
|||||||
pub fn warn_level(&self, config: &TankConfig) -> Result<bool, TankError> {
|
pub fn warn_level(&self, config: &TankConfig) -> Result<bool, TankError> {
|
||||||
match self {
|
match self {
|
||||||
TankState::TankSensorDisabled => Err(TankError::SensorDisabled),
|
TankState::TankSensorDisabled => Err(TankError::SensorDisabled),
|
||||||
TankState::TankSensorError(err) => match err {
|
TankState::TankSensorError(err) => Err(err.clone()),
|
||||||
TankError::SensorValueError { value, min, max } => Ok(value < min),
|
|
||||||
_ => Err(err.clone()),
|
|
||||||
},
|
|
||||||
TankState::TankSensorPresent(raw_value_mv) => {
|
TankState::TankSensorPresent(raw_value_mv) => {
|
||||||
let tank_fill_percent = raw_voltage_to_tank_fill_percent(*raw_value_mv, config)?;
|
let tank_fill_percent = raw_voltage_to_tank_fill_percent(*raw_value_mv, config);
|
||||||
if tank_fill_percent < config.tank_warn_percent.into() {
|
match tank_fill_percent {
|
||||||
Ok(true)
|
Ok(value) => {
|
||||||
} else {
|
if value < config.tank_warn_percent.into() {
|
||||||
Ok(false)
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => match err {
|
||||||
|
TankError::SensorValueError { value, min, max: _ } => Ok(value < min),
|
||||||
|
_ => Err(err),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,6 +136,11 @@ impl TankState {
|
|||||||
TankState::TankSensorPresent(raw_value_mv) => Some(*raw_value_mv),
|
TankState::TankSensorPresent(raw_value_mv) => Some(*raw_value_mv),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let percent = match raw {
|
||||||
|
Some(r) => raw_voltage_to_tank_fill_percent(r, config).ok(),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
TankInfo {
|
TankInfo {
|
||||||
enough_water,
|
enough_water,
|
||||||
warn_level,
|
warn_level,
|
||||||
@ -142,6 +152,7 @@ impl TankState {
|
|||||||
.is_ok_and(|temp| *temp < WATER_FROZEN_THRESH),
|
.is_ok_and(|temp| *temp < WATER_FROZEN_THRESH),
|
||||||
water_temp: water_temp.as_ref().copied().ok(),
|
water_temp: water_temp.as_ref().copied().ok(),
|
||||||
temp_sensor_error: water_temp.err().map(|err| err.to_string()),
|
temp_sensor_error: water_temp.err().map(|err| err.to_string()),
|
||||||
|
percent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,6 +184,8 @@ pub struct TankInfo {
|
|||||||
sensor_error: Option<TankError>,
|
sensor_error: Option<TankError>,
|
||||||
/// raw water sensor value
|
/// raw water sensor value
|
||||||
raw: Option<f32>,
|
raw: Option<f32>,
|
||||||
|
/// percent value
|
||||||
|
percent: Option<f32>,
|
||||||
/// water in tank might be frozen
|
/// water in tank might be frozen
|
||||||
water_frozen: bool,
|
water_frozen: bool,
|
||||||
/// water temperature
|
/// water temperature
|
||||||
|
Loading…
x
Reference in New Issue
Block a user