retry
This commit is contained in:
parent
1711b3d6ea
commit
2104a2f0b0
|
@ -1,7 +1,7 @@
|
|||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::{collections::HashMap, path::PathBuf, time::Duration};
|
||||
|
||||
use clap::Parser;
|
||||
use homekit_controller::{ConnectedDevice, HomekitError, ServiceType};
|
||||
|
@ -45,7 +45,18 @@ async fn init(pairing_data: PathBuf) -> Result<HashMap<String, ConnectedDevice>,
|
|||
let devices = homekit_controller::load(pairing_data)?;
|
||||
let mut connected_devices = HashMap::new();
|
||||
for (k, v) in devices {
|
||||
connected_devices.insert(k, v.connect().await?);
|
||||
let mut num = 0;
|
||||
let connected = loop {
|
||||
if let Ok(v) = v.connect().await {
|
||||
break Some(v);
|
||||
}
|
||||
num += 1;
|
||||
if num > 10 {
|
||||
break None;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
};
|
||||
connected_devices.insert(k, connected.ok_or(HomekitError::DeviceNotFound)?);
|
||||
}
|
||||
Ok(connected_devices)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue