aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--widgets/bat.lua13
1 files changed, 6 insertions, 7 deletions
diff --git a/widgets/bat.lua b/widgets/bat.lua
index cf953a9..25a3aac 100644
--- a/widgets/bat.lua
+++ b/widgets/bat.lua
@@ -10,7 +10,6 @@ local string = { format = string.format }
local helpers = require("vicious.helpers")
local math = {
min = math.min,
- max = math.max,
floor = math.floor
}
-- }}}
@@ -57,9 +56,9 @@ local function worker(format, warg)
-- Get charge information
if battery.current_now then
- rate = battery.current_now
+ rate = tonumber(battery.current_now)
elseif battery.power_now then
- rate = battery.power_now
+ rate = tonumber(battery.power_now)
else
return {state, percent, "N/A"}
end
@@ -67,7 +66,7 @@ local function worker(format, warg)
-- Calculate remaining (charging or discharging) time
local time = "N/A"
- if tonumber(rate) then
+ if rate ~= nil and rate ~= 0 then
if state == "+" then
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
elseif state == "-" then
@@ -76,9 +75,9 @@ local function worker(format, warg)
return {state, percent, time}
end
- -- Calculate time (but work around broken BAT/ACPI implementations)
- local hoursleft = math.max(math.floor(timeleft), 0)
- local minutesleft = math.max(math.floor((timeleft - hoursleft) * 60 ), 0)
+ -- Calculate time
+ local hoursleft = math.floor(timeleft)
+ local minutesleft = math.floor((timeleft - hoursleft) * 60 )
time = string.format("%02d:%02d", hoursleft, minutesleft)
end