summaryrefslogtreecommitdiff
path: root/battery-widget
diff options
context:
space:
mode:
authorStefan Huber <shuber@sthu.org>2022-12-30 12:59:09 +0100
committerStefan Huber <shuber@sthu.org>2022-12-30 12:59:09 +0100
commit0aba2f2e13cc4a20a0b8ab87535cd3ebc61ea66a (patch)
treea3e64315c215a89ffacc3ee8da8b72c3c4b6d898 /battery-widget
parent3bb3d56c26ac3500aab33381af0cccebf6aaa05c (diff)
battery-widget: Simplify capacity computation
Increase cohesion of code that computes total charge and total capacity.
Diffstat (limited to 'battery-widget')
-rw-r--r--battery-widget/battery.lua5
1 files changed, 1 insertions, 4 deletions
diff --git a/battery-widget/battery.lua b/battery-widget/battery.lua
index 452d7ef..935f680 100644
--- a/battery-widget/battery.lua
+++ b/battery-widget/battery.lua
@@ -135,10 +135,6 @@ local function worker(user_args)
end
local capacity = 0
- for _, cap in ipairs(capacities) do
- capacity = capacity + cap
- end
-
local charge = 0
local status
for i, batt in ipairs(battery_info) do
@@ -149,6 +145,7 @@ local function worker(user_args)
end
charge = charge + batt.charge * capacities[i]
+ capacity = capacity + capacities[i]
end
end
charge = charge / capacity