mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix tests
This commit is contained in:
@@ -13,7 +13,6 @@ pub struct LedSupportData {
|
||||
/// This can be many different types of name:
|
||||
/// - `/sys/class/dmi/id/board_name` (must use for laptops)
|
||||
/// - The device name from `lsusb`
|
||||
/// - The product ID (usb only)
|
||||
///
|
||||
/// The laptop board_name is found via `cat /sys/class/dmi/id/board_name`,
|
||||
/// e.g `GU603ZW`. The match doesn't have to be the complete model
|
||||
@@ -26,16 +25,19 @@ pub struct LedSupportData {
|
||||
/// If using a device name the match is similar to the above where it can be
|
||||
/// partial, so `ASUSTek Computer, Inc. ROG STRIX Arion` can be `STRIX
|
||||
/// Arion` for short. Case insensitive.
|
||||
///
|
||||
pub device_name: String,
|
||||
/// The product ID (usb only)
|
||||
/// Example of using a product ID is:
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// $ lsusb
|
||||
/// $ Bus 003 Device 003: ID 0b05:19b6 ASUSTek Computer, Inc. N-KEY Device
|
||||
/// ```
|
||||
/// here `19b6` is all that is required. Case insensitive.
|
||||
pub device_name: String,
|
||||
#[serde(default)]
|
||||
pub product_id: String,
|
||||
/// Keyboard or device LED layout, this is the name of the externally
|
||||
/// defined layout file. Optional, can be an empty string
|
||||
#[serde(default)]
|
||||
pub layout_name: String,
|
||||
/// If empty will default to `Static` mode
|
||||
pub basic_modes: Vec<AuraModeNum>,
|
||||
@@ -43,9 +45,11 @@ pub struct LedSupportData {
|
||||
/// 4 zones and may have a logo and lightbar.
|
||||
///
|
||||
/// Ignored if empty.
|
||||
#[serde(default)]
|
||||
pub basic_zones: Vec<AuraZone>,
|
||||
/// `Zoned` or `PerKey`.
|
||||
// TODO: remove and use layouts only
|
||||
#[serde(default)]
|
||||
pub advanced_type: AdvancedAuraType,
|
||||
/// If empty will default to `Keyboard` power zone
|
||||
pub power_zones: Vec<PowerZones>,
|
||||
@@ -55,13 +59,13 @@ impl LedSupportData {
|
||||
/// Find the data for the device. This function will check DMI info for
|
||||
/// matches against laptops first, then will proceed with matching the
|
||||
/// `device_name` if there are no DMI matches.
|
||||
pub fn get_data(_device_name: &str) -> Self {
|
||||
pub fn get_data(product_id: &str) -> Self {
|
||||
let dmi = DMIID::new().unwrap_or_default();
|
||||
// let prod_family = dmi.product_family().expect("Could not get
|
||||
// product_family");
|
||||
|
||||
if let Some(data) = LedSupportFile::load_from_supoprt_db() {
|
||||
if let Some(data) = data.match_device(&dmi.board_name) {
|
||||
if let Some(data) = data.match_device(&dmi.board_name, product_id) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -80,10 +84,18 @@ impl LedSupportFile {
|
||||
|
||||
/// The list is stored in ordered format, so the iterator must be reversed
|
||||
/// to ensure we match to *whole names* first before doing a glob match
|
||||
fn match_device(&self, device_name: &str) -> Option<LedSupportData> {
|
||||
fn match_device(&self, device_name: &str, product_id: &str) -> Option<LedSupportData> {
|
||||
for config in self.0.iter().rev() {
|
||||
if device_name.contains(&config.device_name) {
|
||||
info!("LedSupport: Matched to {}", config.device_name);
|
||||
info!("Matched to {}", config.device_name);
|
||||
if !config.product_id.is_empty() {
|
||||
info!("Checking product ID");
|
||||
if config.product_id == product_id {
|
||||
return Some(config.clone());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return Some(config.clone());
|
||||
}
|
||||
}
|
||||
@@ -157,6 +169,7 @@ mod tests {
|
||||
fn check_data_parse() {
|
||||
let led = LedSupportData {
|
||||
device_name: "Test".to_owned(),
|
||||
product_id: String::new(),
|
||||
layout_name: "ga401".to_owned(),
|
||||
basic_modes: vec![AuraModeNum::Static],
|
||||
basic_zones: vec![AuraZone::Key1, AuraZone::Logo, AuraZone::BarLeft],
|
||||
|
||||
@@ -4,6 +4,9 @@ use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::Type;
|
||||
|
||||
// TODO: GZ301Z
|
||||
// 5dbcd0010300000a00ff0000ff0000ff0000ff0000ff0000ff0000ff0000ff0000ff0000ff0000
|
||||
|
||||
/// The `LedCode` used in setting up keyboard layouts is important because it
|
||||
/// determines the idexing for an RGB value in the final USB packets (for
|
||||
/// per-key addressable keyboards).
|
||||
|
||||
@@ -531,6 +531,10 @@ mod tests {
|
||||
data_path.push("loop_prep");
|
||||
|
||||
for config in data.get().iter().rev() {
|
||||
if config.layout_name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf.clear();
|
||||
|
||||
let layout_file = format!("{}_US.ron", config.layout_name);
|
||||
|
||||
@@ -305,7 +305,7 @@ mod test {
|
||||
assert_eq!(bytes, [0x04, 0x05, 0x02, 0x00]);
|
||||
|
||||
let bytes = AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
zone: PowerZones::None,
|
||||
awake: false,
|
||||
boot: false,
|
||||
sleep: true,
|
||||
@@ -316,7 +316,7 @@ mod test {
|
||||
assert_eq!(bytes, [0x30, 0x08, 0x04, 0x00]);
|
||||
|
||||
let bytes = AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
zone: PowerZones::None,
|
||||
awake: false,
|
||||
boot: true,
|
||||
sleep: false,
|
||||
@@ -353,140 +353,180 @@ mod test {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let boot_keyb_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let sleep_logo = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let sleep_keyb = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let awake_logo = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
boot: false,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let awake_keyb = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: false,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let shut_logo_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_keyb_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_bar__ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let awake_bar_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
boot: false,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let sleep_bar_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let shut_bar__ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_lid__ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let awake_lid_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
boot: false,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let sleep_lid_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let shut_lid__ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_rear_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let awake_rear = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
boot: false,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let sleep_rear = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
shutdown: false,
|
||||
}],
|
||||
});
|
||||
let shut_rear_ = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -515,9 +555,30 @@ mod test {
|
||||
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
|
||||
|
||||
// All on
|
||||
let byte1 =
|
||||
LaptopAuraPower::new(AuraDeviceType::LaptopPost2021, &LedSupportData::default());
|
||||
let out = to_binary_string(&byte1);
|
||||
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
|
||||
let byte1 = to_binary_string(&LaptopAuraPower {
|
||||
states: vec![
|
||||
AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
..Default::default()
|
||||
},
|
||||
AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
..Default::default()
|
||||
},
|
||||
AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
..Default::default()
|
||||
},
|
||||
AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
..Default::default()
|
||||
},
|
||||
AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
..Default::default()
|
||||
},
|
||||
],
|
||||
});
|
||||
assert_eq!(byte1, "11111111, 00011110, 00001111, 00001111");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user