mirror of https://github.com/lcpz/lain.git
fixing issue in case of nil rate_power in bat widget
This commit is contained in:
parent
49d493e1a4
commit
6cd0a29535
|
@ -94,17 +94,19 @@ local function worker(args)
|
||||||
|
|
||||||
local rate_time = 0
|
local rate_time = 0
|
||||||
if bat_now.status == "Charging" then
|
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
|
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
|
end
|
||||||
|
|
||||||
local hours = math.floor(rate_time)
|
local hours = math.floor(rate_time)
|
||||||
local minutes = math.floor((rate_time - hours) * 60)
|
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.perc = string.format("%d", energy_percentage)
|
||||||
bat_now.time = string.format("%02d:%02d", hours, minutes)
|
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
|
end
|
||||||
|
|
||||||
widget = bat.widget
|
widget = bat.widget
|
||||||
|
|
Loading…
Reference in New Issue