use same output for moisture on webpage as in mqtt

This commit is contained in:
2025-05-19 12:16:09 +02:00
parent 171b130a29
commit 9f48b46738
4 changed files with 28 additions and 20 deletions

View File

@@ -21,6 +21,7 @@ use std::{
use url::Url;
use crate::config::PlantControllerConfig;
use crate::plant_state::MoistureSensorState;
#[derive(Serialize, Debug)]
struct SSIDList<'a> {
@@ -35,8 +36,8 @@ struct LoadData<'a> {
#[derive(Serialize, Debug)]
struct Moistures {
moisture_a: Vec<Option<f32>>,
moisture_b: Vec<Option<f32>>,
moisture_a: Vec<std::string::String>,
moisture_b: Vec<std::string::String>,
}
#[derive(Deserialize, Debug)]
@@ -122,12 +123,28 @@ fn get_live_moisture(
let a = Vec::from_iter(
plant_state
.iter()
.map(|s| s.sensor_a.moisture_percent().map(|f| f.to_precision(2))),
.map(|s| {
match &s.sensor_a {
MoistureSensorState::Disabled => "disabled".to_string(),
MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => {
format!("{moisture_percent:.2}% {raw_hz}hz",)
}
MoistureSensorState::SensorError(err) => format!("{err:?}"),
}
})
);
let b = Vec::from_iter(
plant_state
.iter()
.map(|s| s.sensor_b.moisture_percent().map(|f| f.to_precision(2))),
.map(|s| {
match &s.sensor_b {
MoistureSensorState::Disabled => "disabled".to_string(),
MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => {
format!("{moisture_percent:.2}% {raw_hz}hz",)
}
MoistureSensorState::SensorError(err) => format!("{err:?}"),
}
})
);
let data = Moistures {