1786892891

This commit is contained in:
2026-08-16 17:08:11 +02:00
parent 22c12f4793
commit 475caa9c99
2 changed files with 22 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
use std::{thread::sleep, time::Duration}; use std::time::Duration;
use tokio::sync::mpsc::UnboundedSender; use tokio::{sync::mpsc::UnboundedSender, time::sleep};
use crate::{error::AppError, messages::EventMessage}; use crate::{error::AppError, messages::EventMessage};
@@ -12,14 +12,20 @@ pub async fn battery_listener(s2c_tx: UnboundedSender<EventMessage>) -> Result<(
.next() .next()
.ok_or_else(|| AppError::NoBattery)??; .ok_or_else(|| AppError::NoBattery)??;
tokio::spawn({
let s2c_tx = s2c_tx.clone();
async move {
loop { loop {
println!("huh?");
battery.refresh()?;
s2c_tx s2c_tx
.send(EventMessage::BatteryPercentage(battery.state_of_charge())) .send(EventMessage::BatteryPercentage(battery.state_of_charge()))
.ok(); .ok();
sleep(Duration::from_secs(30)); sleep(Duration::from_secs(30)).await;
battery.refresh().ok();
} }
} }
});
Ok(())
}

View File

@@ -43,7 +43,12 @@ async fn main() -> Result<(), AppError> {
}); });
// start pulling data // start pulling data
tokio::spawn(home_assistant::hass(s2c_tx, c2s_rx)); tokio::spawn({
let s2c_tx = s2c_tx.clone();
async move {
home_assistant::hass(s2c_tx, c2s_rx).await.unwrap();
}
});
app.run().map_err(Into::into) app.run().map_err(Into::into)
} }