Simplified ioreg, added tests for no status
parent
6b97283cbf
commit
601202e816
|
|
@ -68,7 +68,7 @@ battery_percentage(){
|
||||||
echo ${PMSET_OUTPUT:--1}
|
echo ${PMSET_OUTPUT:--1}
|
||||||
elif _command_exists ioreg;
|
elif _command_exists ioreg;
|
||||||
then
|
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}
|
echo ${IOREG_OUTPUT:--1}
|
||||||
elif _command_exists WMIC;
|
elif _command_exists WMIC;
|
||||||
then
|
then
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,15 @@ function setup_pmset {
|
||||||
assert_output "4"
|
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
|
# acpi
|
||||||
|
|
@ -254,3 +263,12 @@ function setup_ioreg {
|
||||||
run battery_percentage
|
run battery_percentage
|
||||||
assert_output "4"
|
assert_output "4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test 'plugins battery: battery-percentage with ioreg, no status' {
|
||||||
|
setup_command_exists "ioreg"
|
||||||
|
|
||||||
|
setup_ioreg ""
|
||||||
|
|
||||||
|
run battery_percentage
|
||||||
|
assert_output "0"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue