fix the Weird Errors caused (?) by opt-level, plus minor tweaks

This commit is contained in:
Alex Janka 2024-03-09 09:01:47 +11:00
parent af3a618529
commit ce989d70af
7 changed files with 30 additions and 13 deletions

8
.cargo/config.toml Normal file
View file

@ -0,0 +1,8 @@
[profile.release]
# somehow there are errors connecting to some devices
# - on linux
# - on release builds
# - when there are other devices too
# so i have turned the opt-level down to prevent this
# one day i will discover the root cause
opt-level = 0

4
Cargo.lock generated
View file

@ -1120,7 +1120,7 @@ dependencies = [
[[package]] [[package]]
name = "homekit-controller" name = "homekit-controller"
version = "0.3.0" version = "0.4.1"
dependencies = [ dependencies = [
"chacha20poly1305", "chacha20poly1305",
"ed25519-dalek", "ed25519-dalek",
@ -1143,7 +1143,7 @@ dependencies = [
[[package]] [[package]]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.4.0" version = "0.4.1"
dependencies = [ dependencies = [
"clap", "clap",
"env_logger", "env_logger",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "homekit-controller" name = "homekit-controller"
version = "0.3.0" version = "0.4.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -340,6 +340,8 @@ impl DeviceConnection {
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum HomekitError { pub enum HomekitError {
#[error("could not connect to any devices")]
NoSuccessfulConnections,
#[error("connection")] #[error("connection")]
Connection(#[from] ConnectionError), Connection(#[from] ConnectionError),
#[error("io")] #[error("io")]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.4.0" version = "0.4.1"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
description = "Prometheus exporter for HomeKit sensors" description = "Prometheus exporter for HomeKit sensors"

View file

@ -1,7 +1,7 @@
# Maintainer: Alex Janka <alex@alexjanka.com> # Maintainer: Alex Janka <alex@alexjanka.com>
pkgname=homekit-logger pkgname=homekit-logger
pkgver=0.4.0 pkgver=0.4.1
pkgrel=1 pkgrel=1
pkgdesc="Prometheus exporter for HomeKit sensors" pkgdesc="Prometheus exporter for HomeKit sensors"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')

View file

@ -79,22 +79,29 @@ async fn init(pairing_data: PathBuf) -> Result<HashMap<String, DeviceConnection>
let mut connected_devices = HashMap::new(); let mut connected_devices = HashMap::new();
for (k, v) in devices { for (k, v) in devices {
let mut num = 0; let mut num = 0;
let connected = loop { loop {
match v.connect(&discovered).await { match v.connect(&discovered).await {
Ok(v) => break Some(v), Ok(v) => {
connected_devices.insert(k, v);
break;
}
Err(e) => { Err(e) => {
num += 1; num += 1;
log::error!("error connecting to {k}: {e:?}");
if num > 10 { if num > 10 {
log::error!("error connecting to {k}: {e:?}"); log::error!("\t...not connecting");
break None; break;
} }
} }
} }
tokio::time::sleep(Duration::from_millis(250)).await; tokio::time::sleep(Duration::from_millis(1000)).await;
}; }
connected_devices.insert(k, connected.ok_or(HomekitError::DeviceNotFound)?); }
if connected_devices.is_empty() {
Err(HomekitError::NoSuccessfulConnections)
} else {
Ok(connected_devices)
} }
Ok(connected_devices)
} else { } else {
log::error!("{:?} is not a file!", pairing_data); log::error!("{:?} is not a file!", pairing_data);
Err(HomekitError::NoPairingData) Err(HomekitError::NoPairingData)