From: aajjbb Date: Sun, 3 Apr 2016 17:07:37 +0000 (-0300) Subject: fixing issue in case of nil rate_power in bat widget X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/6cd0a29535e70d4f1c861cbf97ca482b949e20ee?hp=-c fixing issue in case of nil rate_power in bat widget --- 6cd0a29535e70d4f1c861cbf97ca482b949e20ee diff --git a/widgets/bat.lua b/widgets/bat.lua index d84883e..f20034b 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -94,17 +94,19 @@ local function worker(args) local rate_time = 0 if bat_now.status == "Charging" then - rate_time = (energy_full - energy_now) / rate_power or rate_current + rate_time = (energy_full - energy_now) / rate_power or rate_current elseif bat_now.status == "Discharging" then - rate_time = energy_now / rate_power or rate_current + rate_time = energy_now / (rate_power or rate_current) end local hours = math.floor(rate_time) local minutes = math.floor((rate_time - hours) * 60) - + + local watt = rate_power and (rate_power / 1e6) or (rate_voltage * rate_current) / 1e12 + bat_now.perc = string.format("%d", energy_percentage) bat_now.time = string.format("%02d:%02d", hours, minutes) - bat_now.watt = string.format("%.2fW", rate_power / 1e6 or (rate_voltage * rate_current) / 1e12) + bat_now.watt = string.format("%.2fW", watt) end widget = bat.widget