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 <[email protected]> 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 [email protected].
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/qtile-dev/CAHErDQhUqOzbFX3fKeLYV8MBaKk7yY9ubBSzO9LDEObXUW3Tvg%40mail.gmail.com.

Reply via email to