mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-30 02:38:11 -07:00
tplink: Implement battery level support
This commit is contained in:
committed by
Cooper Quintin
parent
dac838eea9
commit
5ccdcc8685
@@ -13,6 +13,7 @@ use crate::{
|
|||||||
|
|
||||||
pub mod orbic;
|
pub mod orbic;
|
||||||
pub mod tmobile;
|
pub mod tmobile;
|
||||||
|
pub mod tplink;
|
||||||
pub mod wingtech;
|
pub mod wingtech;
|
||||||
|
|
||||||
const LOW_BATTERY_LEVEL: u8 = 10;
|
const LOW_BATTERY_LEVEL: u8 = 10;
|
||||||
@@ -50,6 +51,7 @@ pub async fn get_battery_status(device: &Device) -> Result<BatteryState, Rayhunt
|
|||||||
Device::Orbic => orbic::get_battery_state().await?,
|
Device::Orbic => orbic::get_battery_state().await?,
|
||||||
Device::Wingtech => wingtech::get_battery_state().await?,
|
Device::Wingtech => wingtech::get_battery_state().await?,
|
||||||
Device::Tmobile => tmobile::get_battery_state().await?,
|
Device::Tmobile => tmobile::get_battery_state().await?,
|
||||||
|
Device::Tplink => tplink::get_battery_state().await?,
|
||||||
_ => return Err(RayhunterError::FunctionNotSupportedForDeviceError),
|
_ => return Err(RayhunterError::FunctionNotSupportedForDeviceError),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
use crate::{battery::BatteryState, error::RayhunterError};
|
||||||
|
|
||||||
|
pub async fn get_battery_state() -> Result<BatteryState, RayhunterError> {
|
||||||
|
let uci_battery = tokio::process::Command::new("uci")
|
||||||
|
.arg("get")
|
||||||
|
.arg("battery.battery_mgr.power_level")
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let uci_plugged_in = tokio::process::Command::new("uci")
|
||||||
|
.arg("get")
|
||||||
|
.arg("battery.battery_mgr.is_charging")
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !uci_battery.status.success() {
|
||||||
|
return Err(RayhunterError::BatteryLevelParseError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !uci_plugged_in.status.success() {
|
||||||
|
return Err(RayhunterError::BatteryPluggedInStatusParseError);
|
||||||
|
}
|
||||||
|
|
||||||
|
let uci_battery = String::from_utf8_lossy(&uci_battery.stdout)
|
||||||
|
.trim_end()
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| RayhunterError::BatteryLevelParseError)?;
|
||||||
|
|
||||||
|
let uci_plugged_in = match String::from_utf8_lossy(&uci_plugged_in.stdout).trim_end() {
|
||||||
|
"0" => Ok(false),
|
||||||
|
"1" => Ok(true),
|
||||||
|
_ => Err(RayhunterError::BatteryPluggedInStatusParseError),
|
||||||
|
}?;
|
||||||
|
|
||||||
|
Ok(BatteryState {
|
||||||
|
level: uci_battery,
|
||||||
|
is_plugged_in: uci_plugged_in,
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user