1786892891
This commit is contained in:
@@ -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};
|
||||
|
||||
@@ -12,14 +12,20 @@ pub async fn battery_listener(s2c_tx: UnboundedSender<EventMessage>) -> Result<(
|
||||
.next()
|
||||
.ok_or_else(|| AppError::NoBattery)??;
|
||||
|
||||
loop {
|
||||
println!("huh?");
|
||||
battery.refresh()?;
|
||||
tokio::spawn({
|
||||
let s2c_tx = s2c_tx.clone();
|
||||
async move {
|
||||
loop {
|
||||
s2c_tx
|
||||
.send(EventMessage::BatteryPercentage(battery.state_of_charge()))
|
||||
.ok();
|
||||
|
||||
s2c_tx
|
||||
.send(EventMessage::BatteryPercentage(battery.state_of_charge()))
|
||||
.ok();
|
||||
sleep(Duration::from_secs(30)).await;
|
||||
|
||||
sleep(Duration::from_secs(30));
|
||||
}
|
||||
battery.refresh().ok();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -43,7 +43,12 @@ async fn main() -> Result<(), AppError> {
|
||||
});
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user