aboutsummaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2011-02-21 06:46:49 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2011-02-21 06:46:49 +0100
commit31d7b2fc6b7d9951efcdae23ac00f6106cca7785 (patch)
tree0e993e2703dc61026bac53b74a753ffa9089f138 /widgets
parentd38584386dabc5cba4652b5c285b8389a2b4d415 (diff)
downloadvicious-legacy-31d7b2fc6b7d9951efcdae23ac00f6106cca7785.tar.xz
bat: fixed "no such device" for current and power
Diffstat (limited to 'widgets')
-rw-r--r--widgets/bat.lua21
1 files changed, 12 insertions, 9 deletions
diff --git a/widgets/bat.lua b/widgets/bat.lua
index 1641252..4d9b06c 100644
--- a/widgets/bat.lua
+++ b/widgets/bat.lua
@@ -64,16 +64,19 @@ local function worker(format, warg)
end
-- Calculate remaining (charging or discharging) time
- if state == "+" then
- timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
- elseif state == "-" then
- timeleft = tonumber(remaining) / tonumber(rate)
- else
- return {state, percent, "N/A"}
+ local time = "N/A"
+ if rate ~= nil then
+ if state == "+" then
+ timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
+ elseif state == "-" then
+ timeleft = tonumber(remaining) / tonumber(rate)
+ else
+ return {state, percent, time}
+ end
+ local hoursleft = math.floor(timeleft)
+ local minutesleft = math.floor((timeleft - hoursleft) * 60 )
+ time = string.format("%02d:%02d", hoursleft, minutesleft)
end
- local hoursleft = math.floor(timeleft)
- local minutesleft = math.floor((timeleft - hoursleft) * 60 )
- local time = string.format("%02d:%02d", hoursleft, minutesleft)
return {state, percent, time}
end