diff --git a/Cargo.lock b/Cargo.lock index 5972d2b..19b12bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,6 +352,23 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "battery" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b624268937c0e0a3edb7c27843f9e547c320d730c610d3b8e6e8e95b2026e4" +dependencies = [ + "cfg-if", + "core-foundation 0.7.0", + "lazycell", + "libc", + "mach", + "nix 0.19.1", + "num-traits", + "uom", + "winapi", +] + [[package]] name = "bincode" version = "2.0.1" @@ -738,16 +755,32 @@ dependencies = [ "x11-clipboard", ] +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys 0.7.0", + "libc", +] + [[package]] name = "core-foundation" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ - "core-foundation-sys", + "core-foundation-sys 0.8.7", "libc", ] +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -761,7 +794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "core-graphics-types", "foreign-types", "libc", @@ -774,7 +807,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "libc", ] @@ -784,7 +817,7 @@ version = "20.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5" dependencies = [ - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "foreign-types", "libc", @@ -898,6 +931,7 @@ checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" name = "dashboard" version = "0.1.0" dependencies = [ + "battery", "chrono", "dotenvy", "hass-rs", @@ -1339,7 +1373,7 @@ checksum = "2c7e611d49285d4c4b2e1727b72cf05353558885cc5252f93707b845dfcaf3d3" dependencies = [ "bitflags 2.13.1", "byteorder", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "core-text", "dirs", @@ -2124,7 +2158,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" dependencies = [ "android_system_properties", - "core-foundation-sys", + "core-foundation-sys 0.8.7", "iana-time-zone-haiku", "js-sys", "log", @@ -2595,6 +2629,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "lebe" version = "0.5.3" @@ -2771,6 +2811,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -2903,6 +2952,18 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2" +dependencies = [ + "bitflags 1.3.2", + "cc", + "cfg-if", + "libc", +] + [[package]] name = "nix" version = "0.29.0" @@ -5258,6 +5319,16 @@ version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" +[[package]] +name = "uom" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e76503e636584f1e10b9b3b9498538279561adcef5412927ba00c2b32c4ce5ed" +dependencies = [ + "num-traits", + "typenum", +] + [[package]] name = "ureq" version = "3.4.0" @@ -5835,7 +5906,7 @@ dependencies = [ "calloop 0.13.0", "cfg_aliases", "concurrent-queue", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "cursor-icon", "dpi", diff --git a/build b/build index 369cc49..f644df6 100755 --- a/build +++ b/build @@ -7,7 +7,8 @@ fi ssh -t trekstor -- "systemctl --user stop dashboard" scp target/release/dashboard trekstor:~/dashboard -ssh -t trekstor -- "systemctl --user start dashboard" +# ssh -t trekstor -- "systemctl --user start dashboard" +ssh -t trekstor -- "~/dashboard" git add . git commit -am "$(date +%s)" diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 6fe27c7..364fb6a 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -17,6 +17,7 @@ paste = "1.0.15" ureq = { version = "3.4.0", default-features = false, features = ["json", "rustls"] } serde = { version = "1.0.229", features = ["derive"] } plotters = "0.3.7" +battery = "0.7.8" [features] dev = ["slint/backend-winit-x11"] diff --git a/dashboard/src/error.rs b/dashboard/src/error.rs index df15fa7..d73b1eb 100644 --- a/dashboard/src/error.rs +++ b/dashboard/src/error.rs @@ -17,4 +17,7 @@ pub enum AppError { #[error(transparent)] HomeAssistant(#[from] Box), + + #[error(transparent)] + Battery(#[from] battery::Error), } diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index ccd5a64..adb61fd 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -19,6 +19,18 @@ use crate::{ async fn main() -> Result<(), AppError> { dotenvy::dotenv().ok(); + let manager = battery::Manager::new()?; + + for (idx, maybe_battery) in manager.batteries()?.enumerate() { + let battery = maybe_battery?; + println!("Battery #{}:", idx); + println!("Vendor: {:?}", battery.vendor()); + println!("Model: {:?}", battery.model()); + println!("State: {:?}", battery.state()); + println!("Time to full charge: {:?}", battery.time_to_full()); + println!(); + } + #[cfg(not(feature = "dev"))] slint::platform::set_platform(Box::new(trekstor::Trekstor::new())).expect("set platform");