From 31d7b2fc6b7d9951efcdae23ac00f6106cca7785 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 21 Feb 2011 06:46:49 +0100 Subject: [PATCH] bat: fixed "no such device" for current and power --- widgets/bat.lua | 21 ++++++++++++--------- 1 file 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