termux/battery.rs
1use crate::*;
2use serde::Deserialize;
3
4#[derive(Deserialize, Debug, Clone)]
5pub struct BatteryStatus {
6 pub health: String,
7 pub percentage: u8,
8 pub plugged: String,
9 pub status: String,
10 pub temperature: f64,
11 pub current: i32,
12}
13
14/// Get the status of the device battery.
15pub fn status() -> io::Result<BatteryStatus> {
16 let out = run_api_cmd("BatteryStatus")?;
17 Ok(serde_json::from_str(&out).unwrap())
18}
19
20#[test]
21fn test_status() {
22 assert!(status().is_ok())
23}