Handle case where battery is incorrectly detected

On my Windows VM, `battery' reported a battery as present but with a
charge of `N/A' percents. This commit handle this case as no battery
present.
This commit is contained in:
Lucien Cartier-Tilet 2021-05-22 01:25:42 +02:00
parent be0c8859d6
commit e78aaa41f9
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 2 additions and 1 deletions

View File

@ -455,7 +455,8 @@ thought of as the “percentage of discharge” of the computer.
Thus, setting the warning at 75% will be translated as showing
the warning face with a battery level of 25% or less."
(let ((battery-level (battery)))
(if (string= battery-level "Battery status not available")
(if (or (string= battery-level "Battery status not available")
(string-match-p (regexp-quote "N/A") battery-level))
""
(let ((percentage (save-match-data
(string-match "\\([0-9]+\\)\\(\\.[0-9]\\)?%" battery-level)