X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/13a6d1cf457e3c5ed813f74c03b01041115c29c4..86b932b7c120c30e3ad2ce3838018f9e2942f729:/widgets/bat.lua?ds=inline diff --git a/widgets/bat.lua b/widgets/bat.lua index 4a25d63..485fd57 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -75,7 +75,7 @@ local function worker(args) bat_now.status = first_line(bstr .. "/status") or "N/A" - rate = tonumber(rate) + rate = tonumber(rate) or 1 ratev = tonumber(ratev) rem = tonumber(rem) tot = tonumber(tot) @@ -97,13 +97,17 @@ local function worker(args) bat_now.time = string.format("%02d:%02d", hrs, min) - local perc = (rem / tot) * 100 - if perc <= 100 then - bat_now.perc = string.format("%d", perc) - elseif perc > 100 then - bat_now.perc = "100" - elseif perc < 0 then - bat_now.perc = "0" + bat_now.perc = first_line(bstr .. "/capacity") + + if not bat_now.perc then + local perc = (rem / tot) * 100 + if perc <= 100 then + bat_now.perc = string.format("%d", perc) + elseif perc > 100 then + bat_now.perc = "100" + elseif perc < 0 then + bat_now.perc = "0" + end end if rate ~= nil and ratev ~= nil then @@ -118,15 +122,16 @@ local function worker(args) settings() -- notifications for low and critical states - if bat_now.status == "Discharging" and notify == "on" + bat_now.perc = tonumber(bat_now.perc) + if bat_now.status == "Discharging" and notify == "on" and bat_now.perc ~= nil then - if tonumber(bat_now.perc) <= 5 + if bat_now.perc <= 5 then bat.id = naughty.notify({ preset = bat_notification_critical_preset, replaces_id = bat.id }).id - elseif tonumber(bat_now.perc) <= 15 + elseif bat_now.perc <= 15 then bat.id = naughty.notify({ preset = bat_notification_low_preset,