battery icon indicating copy to clipboard operation
battery copied to clipboard

battery maintain with voltage not working

Open neoeleatic opened this issue 1 year ago • 0 comments

The logic to check for voltages in "battery maintain" is slightly broken, resulting in the feature not working.

❯ battery maintain 11.4V
06/28/24-17:39:03 - Called with 11.4 maintain
06/28/24-17:39:03 - Error: 11.4 is not a valid setting for battery maintain. Please use a number between 0 and 100, or an action keyword like 'stop' or 'recover'.

Parts of https://github.com/actuallymentor/battery/pull/224 got rewritten in a subsequent merge, introducing the problem.

This is a quick fix:

--- a/battery.sh
+++ b/battery.sh
@@ -672,10 +672,9 @@ if [[ "$action" == "maintain" ]]; then
        fi
 
        is_voltage=true
-   fi
 
    # Check if setting is value between 0 and 100
-   if ! valid_percentage "$setting"; then
+   elif ! valid_percentage "$setting"; then
        log "Called with $setting $action"
        # If non 0-100 setting is not a special keyword, exit with an error.
        if ! { [[ "$setting" == "stop" ]] || [[ "$setting" == "recover" ]]; }; then

neoeleatic avatar Jun 28 '24 15:06 neoeleatic