mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Test battery search
This commit is contained in:
@@ -47,30 +47,22 @@ impl AsusPower {
|
|||||||
PlatformError::Udev("scan_devices failed".into(), err)
|
PlatformError::Udev("scan_devices failed".into(), err)
|
||||||
})? {
|
})? {
|
||||||
if let Some(attr) = device.attribute_value("type") {
|
if let Some(attr) = device.attribute_value("type") {
|
||||||
match attr.to_os_string().as_os_str().to_str() {
|
info!("Power: Checking {:?}", device.syspath());
|
||||||
Some("Mains") => {
|
match attr.to_string_lossy().to_ascii_lowercase().trim() {
|
||||||
|
"mains" => {
|
||||||
info!("Found mains power at {:?}", device.sysname());
|
info!("Found mains power at {:?}", device.sysname());
|
||||||
mains = device.syspath().to_path_buf();
|
mains = device.syspath().to_path_buf();
|
||||||
}
|
}
|
||||||
Some("Battery") => {
|
"battery" => {
|
||||||
// Priortised list of checks
|
// Priortised list of checks
|
||||||
|
info!("Found a battery");
|
||||||
if battery.is_none() {
|
if battery.is_none() {
|
||||||
// This check required due to an instance where another "not"
|
info!("Checking battery attributes");
|
||||||
// battery can be found
|
if device
|
||||||
if let Some(m) = device.attribute_value("manufacturer") {
|
|
||||||
// Should always be ASUSTeK, but match on a lowercase part to be sure
|
|
||||||
if m.to_string_lossy().to_lowercase().contains("asus") {
|
|
||||||
info!(
|
|
||||||
"Found battery power at {:?}, matched manufacturer",
|
|
||||||
device.sysname()
|
|
||||||
);
|
|
||||||
battery = Some(device.syspath().to_path_buf());
|
|
||||||
}
|
|
||||||
} else if device
|
|
||||||
.attribute_value("charge_control_end_threshold")
|
.attribute_value("charge_control_end_threshold")
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
info!("Found battery power at {:?}, matched charge_control_end_threshold and energy_full_design", device.sysname());
|
info!("Found battery power at {:?}, matched charge_control_end_threshold", device.sysname());
|
||||||
battery = Some(device.syspath().to_path_buf());
|
battery = Some(device.syspath().to_path_buf());
|
||||||
} else if device.sysname().to_string_lossy().starts_with("BAT") {
|
} else if device.sysname().to_string_lossy().starts_with("BAT") {
|
||||||
info!(
|
info!(
|
||||||
@@ -78,18 +70,16 @@ impl AsusPower {
|
|||||||
device.sysname()
|
device.sysname()
|
||||||
);
|
);
|
||||||
battery = Some(device.syspath().to_path_buf());
|
battery = Some(device.syspath().to_path_buf());
|
||||||
} else if let Some(m) = device.attribute_value("type") {
|
} else {
|
||||||
if m.to_string_lossy().to_lowercase().contains("battery") {
|
info!(
|
||||||
info!(
|
"Last resort: Found battery power at {:?} using type = Battery",
|
||||||
"Last resort: Found battery power at {:?}",
|
device.sysname()
|
||||||
device.sysname()
|
);
|
||||||
);
|
battery = Some(device.syspath().to_path_buf());
|
||||||
battery = Some(device.syspath().to_path_buf());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some("USB") => {
|
"usb" => {
|
||||||
info!("Found USB-C power at {:?}", device.sysname());
|
info!("Found USB-C power at {:?}", device.sysname());
|
||||||
usb = Some(device.syspath().to_path_buf());
|
usb = Some(device.syspath().to_path_buf());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user