use crate::protos::power_supply_properties::power_supply_properties;
use crate::protos::power_supply_properties::PowerSupplyProperties;
use crate::BatteryData;
use crate::BatteryStatus;
use crate::PowerData;
pub const POWER_INTERFACE_NAME: &str = "org.chromium.PowerManager";
pub const POWER_OBJECT_PATH: &str = "/org/chromium/PowerManager";
pub mod client;
pub mod monitor;
impl From<PowerSupplyProperties> for PowerData {
fn from(props: PowerSupplyProperties) -> Self {
let ac_online = if props.has_external_power() {
props.external_power() != power_supply_properties::ExternalPower::DISCONNECTED
} else {
false
};
let battery = if props.has_battery_state()
&& props.battery_state() != power_supply_properties::BatteryState::NOT_PRESENT
{
let status = match props.battery_state() {
power_supply_properties::BatteryState::FULL => BatteryStatus::NotCharging,
power_supply_properties::BatteryState::CHARGING => BatteryStatus::Charging,
power_supply_properties::BatteryState::DISCHARGING => BatteryStatus::Discharging,
_ => BatteryStatus::Unknown,
};
let percent = std::cmp::min(100, props.battery_percent().round() as u32);
let voltage = (props.battery_voltage() * 1_000_000f64).round() as u32;
let current = (props.battery_current() * 1_000_000f64).round() as u32;
let charge_counter = (props.battery_charge() * 1_000_000f64).round() as u32;
let charge_full = (props.battery_charge_full() * 1_000_000f64).round() as u32;
Some(BatteryData {
status,
percent,
voltage,
current,
charge_counter,
charge_full,
})
} else {
None
};
Self { ac_online, battery }
}
}