Thanks,

But not what i exactly am looking for, the point is i don't need to know 
each battery capacity but have them combined and displayed as there was one 
battery (status, calculated percentage from both, calculated time remaining 
on battery/to charge from both), the idea is that i don't want to have two 
battery icons or two widgets for each battery but have a single one to 
report the total from both.

There is also some math to do in the script as not two batteries have same 
capacity, internal is smaller and the external is much bigger.
There is someone who did a upower script for exactly the same laptop 
(Lenovo ThinkPad X240) but he does have separated scripts for percentage, 
wattage, time etc.

Link is here: https://github.com/pcchou/dual-battery-thinkpad-upower-script

Unluckily i have no scripting experience to create/merge a single script 
from this link to have the desired output which is as shown in the picture 
below:
[image: battery.png]
So as seen in the picture, this is what i exactly need to display from the 
battery widget in the same order but this should be the calculated output 
from both batteries.
1. The icon/status (full;empty;charging;discharging)
2. The calculated capacity from both batteries 
3. The time remaining on battery (calculated total from both batteries), 
time remaining to charge both batteries).
4. Possibly have like 3 different icons per level : Full battery icon as on 
the picture from 100-75% capacity, a half charged icon from 74-25% and a 
almost empty icon from 24-0%

An if statement in case the laptop has only one battery to not have to 
change anything on the script which i may possibly use on a future laptop 
(like the guy on the link did).

Thanks in advance !
On Tuesday, November 29, 2022 at 4:57:21 AM UTC+1 ja...@jameswright.xyz 
wrote:

> Stumbled on a solution: in the qtile-extras repo, there's a widget that 
> (per documentation) supports multiple batteries:
>
> https://qtile-extras.readthedocs.io/en/stable/manual/ref/widgets.html#upowerwidget
>
> I remembered this thread when I saw it, so figured I'd pass it along. I 
> haven't used it myself, but the qtile-extras package is maintained by one 
> of qtile's core developers.
>
>
> On Tue, Nov 1, 2022, 10:27 James Wright <ja...@jameswright.xyz> wrote:
>
>> I don't know about hard to have the feature, but the steps I would 
>> probably do (going off of `widget/battery.py` in the repository) is to:
>>
>> 1) Create a `class _MultipleBatteries(_Battery)` class for multiple 
>> batteries, which would take as input a list of battery config dictionaries 
>> and a function that takes in a list of `BatteryStatus` objects and returns 
>> some "average" of them as a new `BatteryStatus` object. This latter 
>> function would effectively set the `update_status` method for 
>> `_MultipleBatteries`. 
>> 2) edit `load_battery` so that it will correctly return the correct 
>> `_Battery` object.
>>
>> So pseudo code:
>>
>>   def load_battery(**config) -> _Battery:
>>       """Default battery loading function
>>   
>>       Loads and returns the _Battery interface suitable for the current 
>> running
>>       platform.
>>   
>>       Parameters
>>       ----------
>>       config: Dictionary of config options that are passed to the 
>> generated
>>       battery.
>>   
>>       Return
>>       ------
>>       The configured _Battery for the current platform.
>>       """
>>       system = platform.system()
>>   
>> +     if 'batteries' in config.keys():
>> +         return _MultipleBatteres(**config)
>> ~     elif system == "FreeBSD":
>>           return _FreeBSDBattery(str(config["battery"]))
>>       elif system == "Linux":
>>           return _LinuxBattery(**config)
>>       else:
>>           raise RuntimeError("Unknown platform!")
>>   
>> + class _MultipleBatteries(_Battery):
>> + 
>> +     def __init__(self, config: dict) -> None:
>> +         self.battery_function: Callable[List[BatteryStatus], 
>> BatteryStatus] = config['battery_function']
>> +         self.batteries = []
>> +         for bat in config['batteries']:
>> +             self.batteries.append(load_battery(**bat))
>> + 
>> +     def update_status(self):
>> +         statuses = []
>> +         for battery in self.batteries:
>> +             statuses.append(battery.update_status)
>> +         return self.battery_function(statuses)
>>
>> Unfortunately I don't have time to tackle this myself, but hopefully this 
>> will provide enough info for someone to be able to implement and test it.
>>
>>
>>
>> On Sun, Oct 30, 2022 at 10:32 AM Sniki <besnik.n...@gmail.com> wrote:
>>
>>> Hi everyone, a happy Qtile user here with (i think) the last remaining 
>>> problem not solved.
>>> I have a Lenovo ThinkPad X240 which does have two batteries (internal & 
>>> external)
>>> I have setup the wiget.battery the way i want to but it only can show 
>>> informations for one of the batteries (BAT0 or BAT1).
>>>
>>> Is it hard to have a feature on battery widget to support multiple 
>>> batteries (merge percentage and time remaining from both batteries into 
>>> one).
>>>
>>> Possible current workarounds:
>>> 1. Forced to use two battery widgets but it bloats the bar and not much 
>>> space left for it anyway and having to check both of them is kinda 
>>> exhausting may i say.
>>> 2. Create a script for that (heard people saying it's possible with some 
>>> math/logic) but that is out of my current knowledge level (awk/grep/cat or 
>>> whatever) so i am not able to do that myself.
>>>
>>> config: 
>>> https://gitlab.com/Sniki/dotfiles/-/blob/master/.config/qtile/config.py
>>>
>>> Thanks !
>>>
>>>
>>>
>>>
>>>
>>> config: 
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "qtile-dev" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to qtile-dev+...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/qtile-dev/1055a620-598a-454e-bc72-f41b63e89bden%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/qtile-dev/1055a620-598a-454e-bc72-f41b63e89bden%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to qtile-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/qtile-dev/c0154ff7-9851-4170-b2e8-6909b8682612n%40googlegroups.com.

Reply via email to