From c239dbb2e4164b0f02ebb39dd4514ccbe1640f3c Mon Sep 17 00:00:00 2001 From: Alexander Godlewski Date: Sun, 10 Nov 2024 23:50:18 -0500 Subject: [PATCH] [bat_linux] Fallback to computing (dis)charge rate Co-authored-by: Alexander Godlewski --- CHANGELOG.rst | 7 +++++++ widgets/bat_linux.lua | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8b54eaf..9356c27 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Changelog ========= +Changes in 2.7.1 +---------------- + +Fixed: + +- [bat_linux] Fallback to computing bat (dis)charge rate in some cases + Changes in 2.7.0 ---------------- diff --git a/widgets/bat_linux.lua b/widgets/bat_linux.lua index 186c6e8..96f0065 100644 --- a/widgets/bat_linux.lua +++ b/widgets/bat_linux.lua @@ -4,6 +4,7 @@ -- Copyright (C) 2017 David Udelson -- Copyright (C) 2017 Roberto -- Copyright (C) 2017 mutlusun +-- Copyright (C) 2024 arch-stack -- -- This file is part of Vicious. -- @@ -46,8 +47,13 @@ return helpers.setcall(function (format, warg) -- Get current power usage in watt local curpower = "N/A" + if battery.power_now then curpower = string.format("%.2f", tonumber(battery.power_now) /1000000) + elseif battery.current_now and battery.voltage_now then + local current = tonumber(battery.current_now) + local voltage = tonumber(battery.voltage_now) + curpower = string.format("%.2f", current * voltage / 10^12) end -- Check if the battery is present