Simplified ioreg, added tests for no status

pull/1080/head
Nils Winkler 2017-10-24 07:32:00 +02:00
parent 6b97283cbf
commit 601202e816
2 changed files with 19 additions and 1 deletions

View File

@ -68,7 +68,7 @@ battery_percentage(){
echo ${PMSET_OUTPUT:--1}
elif _command_exists ioreg;
then
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -1)
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%d"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
echo ${IOREG_OUTPUT:--1}
elif _command_exists WMIC;
then

View File

@ -71,6 +71,15 @@ function setup_pmset {
assert_output "4"
}
@test 'plugins battery: battery-percentage with pmset, no status' {
setup_command_exists "pmset"
setup_pmset ""
run battery_percentage
assert_output "-1"
}
#######################
#
# acpi
@ -254,3 +263,12 @@ function setup_ioreg {
run battery_percentage
assert_output "4"
}
@test 'plugins battery: battery-percentage with ioreg, no status' {
setup_command_exists "ioreg"
setup_ioreg ""
run battery_percentage
assert_output "0"
}