Add battery capacity parsing (#216)
The Linux power supply class defines three entries to provide battery status. One of them wasn't used: POWER_SUPPLY_CAPACITY. https://www.kernel.org/doc/Documentation/power/power_supply_class.txt
This commit is contained in:
parent
94651257ce
commit
c7dea74751
@ -138,9 +138,13 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen
|
||||
if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW=")) {
|
||||
watt_as_unit = true;
|
||||
batt_info->remaining = atoi(walk + 1);
|
||||
batt_info->percentage_remaining = -1;
|
||||
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW=")) {
|
||||
watt_as_unit = false;
|
||||
batt_info->remaining = atoi(walk + 1);
|
||||
batt_info->percentage_remaining = -1;
|
||||
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CAPACITY=") && batt_info->remaining == -1) {
|
||||
batt_info->percentage_remaining = atoi(walk + 1);
|
||||
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW="))
|
||||
batt_info->present_rate = abs(atoi(walk + 1));
|
||||
else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW="))
|
||||
|
1
testcases/014-battery-capacity/expected_output.txt
Normal file
1
testcases/014-battery-capacity/expected_output.txt
Normal file
@ -0,0 +1 @@
|
||||
Touchpad: 100.00% BAT
|
13
testcases/014-battery-capacity/i3status.conf
Normal file
13
testcases/014-battery-capacity/i3status.conf
Normal file
@ -0,0 +1,13 @@
|
||||
general {
|
||||
output_format = "none"
|
||||
}
|
||||
|
||||
order += "battery 1"
|
||||
|
||||
battery 1 {
|
||||
format = "Touchpad: %percentage %status %remaining"
|
||||
format_down = "No touchpad"
|
||||
path = "/sys/class/power_supply/hid-ff:ff:ff:ff:ff:ff-battery/uevent"
|
||||
path = "testcases/014-battery-capacity/uevent"
|
||||
low_threshold = 10
|
||||
}
|
7
testcases/014-battery-capacity/uevent
Normal file
7
testcases/014-battery-capacity/uevent
Normal file
@ -0,0 +1,7 @@
|
||||
POWER_SUPPLY_NAME=hid-70:cd:60:f7:a0:5c-battery
|
||||
POWER_SUPPLY_PRESENT=1
|
||||
POWER_SUPPLY_ONLINE=1
|
||||
POWER_SUPPLY_CAPACITY=100
|
||||
POWER_SUPPLY_MODEL_NAME=applemagictrackpad
|
||||
POWER_SUPPLY_STATUS=Discharging
|
||||
POWER_SUPPLY_SCOPE=Device
|
1
testcases/015-battery-capacity/expected_output.txt
Normal file
1
testcases/015-battery-capacity/expected_output.txt
Normal file
@ -0,0 +1 @@
|
||||
Touchpad: 30.64% BAT 02:09:32
|
13
testcases/015-battery-capacity/i3status.conf
Normal file
13
testcases/015-battery-capacity/i3status.conf
Normal file
@ -0,0 +1,13 @@
|
||||
general {
|
||||
output_format = "none"
|
||||
}
|
||||
|
||||
order += "battery 1"
|
||||
|
||||
battery 1 {
|
||||
format = "Touchpad: %percentage %status %remaining"
|
||||
format_down = "No touchpad"
|
||||
path = "/sys/class/power_supply/hid-ff:ff:ff:ff:ff:ff-battery/uevent"
|
||||
path = "testcases/015-battery-capacity/uevent"
|
||||
low_threshold = 10
|
||||
}
|
10
testcases/015-battery-capacity/uevent
Normal file
10
testcases/015-battery-capacity/uevent
Normal file
@ -0,0 +1,10 @@
|
||||
POWER_SUPPLY_CAPACITY=100
|
||||
POWER_SUPPLY_CURRENT_NOW=1107000
|
||||
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
|
||||
POWER_SUPPLY_CHARGE_NOW=2390000
|
||||
POWER_SUPPLY_NAME=hid-70:cd:60:f7:a0:5c-battery
|
||||
POWER_SUPPLY_PRESENT=1
|
||||
POWER_SUPPLY_ONLINE=1
|
||||
POWER_SUPPLY_MODEL_NAME=applemagictrackpad
|
||||
POWER_SUPPLY_STATUS=Discharging
|
||||
POWER_SUPPLY_SCOPE=Device
|
Loading…
Reference in New Issue
Block a user