Unverified Commit 787331e1 authored by Mark Vander Stel's avatar Mark Vander Stel
Browse files

Merge branch 'pr/687'

parents f89a4274 e95618b4
......@@ -187,6 +187,20 @@ General
Features
--------
.. attribute:: LP_BATTERY_ID
:type: int
:value: 0
Select which battery to use when monitoring level and charging status.
Works only with ACPI method of obtaining battery information.
Usage example:
* Default value for this option is ``0``, meaning default battery will
be used when monitoring battery level and charging status.
* Any other value must be a valid battery ID. Can be obtained by running
``acpi --battery`` and getting the appropriate ID from the printout.
.. versionadded:: 2.1
.. attribute:: LP_DELIMITER_KUBECONTEXT_PREFIX
:type: string
......
......@@ -44,6 +44,9 @@ Battery
Can be disabled by :attr:`LP_ENABLE_BATT`.
.. versionchanged:: 2.1
:attr:`LP_BATTERY_ID` can be used to specify which battery to monitor.
Development Environment
-----------------------
......
......@@ -339,6 +339,8 @@ __lp_source_config() {
)
fi
LP_BATTERY_ID=${LP_BATTERY_ID:-0}
# Debugging flags
LP_DEBUG_TIME=${LP_DEBUG_TIME:-0}
......@@ -2343,6 +2345,18 @@ case "$LP_OS" in
(( LP_ENABLE_BATT )) || return 5
local acpi
acpi="$(acpi --battery 2>/dev/null)"
# Check if we want a battery other than the default one
if [[ $LP_BATTERY_ID -gt 0 ]]; then
while IFS=$'\n' read -r line; do
# Find the desired battery by it's ID
if [[ $line =~ Battery\ $LP_BATTERY_ID ]]; then
acpi=$line # Use only desired battery output
break
fi
done <<<"$acpi"
fi
# Extract the battery load value in percent
# First, remove the beginning of the line...
lp_battery="${acpi#Battery *, }"
......
......@@ -20,6 +20,13 @@
# Recommended value is 75
LP_BATTERY_THRESHOLD=75
# Use particular battery ID when multiple batteries are reported by ACPI
# and the default one is wrong.
# Example of such behaviour is when using Logitech Unified Receiver
# and ACPI reports keyboard and mouse batteries first, and laptop battery last
# Run acpi --battery and use Battery # for this value.
LP_BATTERY_ID=0
# Display the load average over the past minute when above this threshold.
# This value is scaled per CPU, so on a quad-core machine, the load average
# would need to be 2.40 or greater to be displayed.
......
......@@ -10,7 +10,7 @@ unset -f uname
LP_ENABLE_BATT=1
typeset -a battery_outputs battery_statuses battery_values temp_outputs temp_values
typeset -a battery_outputs battery_statuses battery_values temp_outputs temp_values battery_ids
# Add test cases to these arrays like below
......@@ -19,6 +19,7 @@ battery_outputs+=(
""
)
battery_statuses+=(4)
battery_ids+=("")
battery_values+=("")
temp_outputs+=(
"Thermal 0: ok, 23.0 degrees C"
......@@ -31,11 +32,26 @@ battery_outputs+=(
)
battery_statuses+=(0)
battery_values+=(55)
battery_ids+=(0)
temp_outputs+=(
"Thermal 0: ok, -267.8 degrees C"
)
temp_values+=(-267)
# Multiple batteries
battery_outputs+=(
"Battery 0: Discharging, 0%, rate information unavailable
Battery 1: Discharging, 0%, rate information unavailable
Battery 2: Discharging, 53%, 02:35:00 remaining"
)
battery_statuses+=(0)
battery_values+=(53)
battery_ids+=(2)
temp_outputs+=(
"Thermal 0: ok, 39.0 degrees C"
)
temp_values+=(39)
# VPS at OVH
temp_outputs+=(
""
......@@ -50,6 +66,7 @@ function test_acpi_battery {
for (( index=0; index < ${#battery_values[@]}; index++ )); do
__battery_output=${battery_outputs[$index]}
LP_BATTERY_ID=${battery_ids[$index]}
LP_BATTERY_THRESHOLD=100
_lp_battery
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment