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};
|
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(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user