From 6cd0a29535e70d4f1c861cbf97ca482b949e20ee Mon Sep 17 00:00:00 2001
From: aajjbb <jefersonlsiq@gmail.com>
Date: Sun, 3 Apr 2016 14:07:37 -0300
Subject: [PATCH 1/1] fixing issue in case of nil rate_power in bat widget

---
 widgets/bat.lua | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

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
-- 
2.39.5