actuallymentor / battery

CLI/GUI for managing the battery charging status for Apple silicon (M1, M32, M3) Macs
MIT License
3.58k stars 148 forks source link

battery maintain with voltage not working #286

Closed neoeleatic closed 3 months ago

neoeleatic commented 3 months ago

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