3 Commits

Author SHA1 Message Date
9c363e3760 refctor: TankInfo structure (consistent layout)
- fix: use tagged enum serialization for TankError
- fix: rename TankInfo fields for consistent naming (volume_ml, pct, water_temp_c)
- renamed some fields for better clarity on contained value
2026-05-10 13:22:38 +02:00
8be98b9447 refactor: PlantInfo structure (consistent layout)
- fix: use tagged enum serialization for MoistureSensorError and PumpError
- fix: flatten PlantInfo sensors to SensorTelemetry with top-level moisture_pct
2026-05-10 13:19:55 +02:00
1d29f3ea5f refactor: BatteryInfo structure (consistent layout)
- use tagged enum serialization for BatteryError
- flatten BatteryInfo telemetry with consistent field names and typed error
2026-05-10 13:19:45 +02:00
3 changed files with 8 additions and 8 deletions

View File

@@ -28,7 +28,7 @@ pub trait BatteryInteraction {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct BatteryInfo { pub struct BatteryInfo {
pub voltage_mv: Option<u16>, pub voltage_mv: Option<u16>,
pub current_ma: Option<i16>, pub avg_current_ma: Option<i16>,
pub soc_pct: Option<f32>, pub soc_pct: Option<f32>,
pub soh_pct: Option<u16>, pub soh_pct: Option<u16>,
pub temperature_c: Option<u16>, pub temperature_c: Option<u16>,
@@ -183,7 +183,7 @@ impl BatteryInteraction for BQ34Z100G1 {
async fn get_battery_state(&mut self) -> FatResult<BatteryState> { async fn get_battery_state(&mut self) -> FatResult<BatteryState> {
Ok(BatteryState::Info(BatteryInfo { Ok(BatteryState::Info(BatteryInfo {
voltage_mv: Some(self.voltage_milli_volt().await?), voltage_mv: Some(self.voltage_milli_volt().await?),
current_ma: Some(self.average_current_milli_ampere().await?), avg_current_ma: Some(self.average_current_milli_ampere().await?),
soc_pct: Some(self.state_charge_percent().await?), soc_pct: Some(self.state_charge_percent().await?),
soh_pct: Some(self.state_health_percent().await?), soh_pct: Some(self.state_health_percent().await?),
temperature_c: Some(self.bat_temperature().await?), temperature_c: Some(self.bat_temperature().await?),

View File

@@ -866,7 +866,7 @@ async fn publish_battery_state(
Ok(BatteryState::Info(info)) => info, Ok(BatteryState::Info(info)) => info,
Ok(BatteryState::Unknown) => BatteryInfo { Ok(BatteryState::Unknown) => BatteryInfo {
voltage_mv: None, voltage_mv: None,
current_ma: None, avg_current_ma: None,
soc_pct: None, soc_pct: None,
soh_pct: None, soh_pct: None,
temperature_c: None, temperature_c: None,
@@ -877,7 +877,7 @@ async fn publish_battery_state(
}, },
Err(e) => BatteryInfo { Err(e) => BatteryInfo {
voltage_mv: None, voltage_mv: None,
current_ma: None, avg_current_ma: None,
soc_pct: None, soc_pct: None,
soh_pct: None, soh_pct: None,
temperature_c: None, temperature_c: None,

View File

@@ -144,13 +144,13 @@ impl TankState {
warn_level, warn_level,
volume_ml: left_ml, volume_ml: left_ml,
sensor_error: tank_err, sensor_error: tank_err,
raw, fill_raw_v: raw,
water_frozen: water_temp water_frozen: water_temp
.as_ref() .as_ref()
.is_ok_and(|temp| *temp < WATER_FROZEN_THRESH), .is_ok_and(|temp| *temp < WATER_FROZEN_THRESH),
water_temp_c: water_temp.as_ref().copied().ok(), water_temp_c: water_temp.as_ref().copied().ok(),
temp_sensor_error: water_temp.as_ref().err().map(|err| err.to_string()), temp_sensor_error: water_temp.as_ref().err().map(|err| err.to_string()),
pct: percent, fill_pct: percent,
} }
} }
} }
@@ -184,9 +184,9 @@ pub struct TankInfo {
/// if there is an issue with the water level sensor /// if there is an issue with the water level sensor
pub(crate) sensor_error: Option<TankError>, pub(crate) sensor_error: Option<TankError>,
/// raw water sensor value /// raw water sensor value
pub(crate) raw: Option<f32>, pub(crate) fill_raw_v: Option<f32>,
/// percent value /// percent value
pub(crate) pct: Option<f32>, pub(crate) fill_pct: Option<f32>,
/// water in the tank might be frozen /// water in the tank might be frozen
pub(crate) water_frozen: bool, pub(crate) water_frozen: bool,
/// water temperature /// water temperature