question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An all battery option.

See original GitHub issue

Feature Request

Instead of having several batteries showing when you have more than one, an idea could be to have an option all for showing a combined result of all of them.

I am currently trying to make one (with my limited skills). I am a little struggling with the whole widget engine but here is the idea I had from the original engine by making a quick script in python.

class Batteries:
    def __init__(self):
        self._batteries = []
        self._batteries.append("/sys/class/power_supply/BAT0")
        self._batteries.append("/sys/class/power_supply/BAT1")

    def widget(self, name):
        for widget in self._widgets:
            if widget.name == name:
                return widget

    def find_capacity(self):
        new_widgets = []
        for path in self._batteries:
            widget = path
            new_widgets.append(widget)
            print(self.capacity(widget))
        print(self.capacity_all(new_widgets))

    def capacity(self, widget):
        try:
            with open("{}/energy_full".format(widget)) as f:
                energy_full = int(f.read())
            with open("{}/energy_now".format(widget)) as o:
                energy_now = int(o.read())
                capacity = int( energy_now / energy_full  * 100)
        except IOError:
            return "n/a"
        capacity = capacity if capacity < 100 else 100
        output =  "{}%".format(capacity)
        return output

    def capacity_all(self, widgets):
        energy_now = 0
        energy_full = 0
        for widget in widgets:
            try:
                with open("{}/energy_full".format(widget)) as f:
                    energy_full += int(f.read())
                with open("{}/energy_now".format(widget)) as o:
                    energy_now += int(o.read())
            except IOError:
                return "n/a"

        capacity = int( energy_now / energy_full  * 100)
        capacity = capacity if capacity < 100 else 100
        output =  "{}%".format(capacity)
        return output




battery = Batteries()

print(battery._batteries)

print(battery.find_capacity())


Summary

Battery combined widget or all option for all the batteries presents instead of them individually.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
martindoublemcommented, Nov 17, 2018

Yes it is dependent on the power library of python. I was trying to look into how it calculates the remaining time but it looks rather complex. I decided to combine it with a manual calculation as it is useful to find the cases of unlimited or unknown.

The results can be found in: #329

0reactions
jonasreitemeyercommented, Dec 27, 2019

Had the same issue and it took some time to get the solution here. My suggestion: Putting a hint into the readme would be great.

Also big thanks to @martindoublem for the module and of course @tobi-wan-kenobi for this awesome status line

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add the battery icon to the taskbar in Windows 10
Under Batteries, right-click the battery for your device, select Disable, and select Yes. Wait a few seconds, and then right-click the battery and...
Read more >
Fixed: Battery Icon Missing or Grayed Out in Windows 10
You can fix this issue by toggling the Power option to show up in your system tray. Right-click on an empty space in...
Read more >
Show the battery percentage on your iPhone or iPad
With iOS 16, you can turn on the battery percentage so it appears in your status bar. Go to Settings > Battery, and...
Read more >
7 Ways to Restore a Missing Battery Icon on the Windows 10 ...
On the Device Manager, double-click the Batteries option to expand it. ... If you've tried all the solutions we've mentioned so far and...
Read more >
Battery Icon Missing on Windows 10? Restore it - Lifewire
Disable and Re-enable Battery Hardware to Reveal Battery Icon · In the Device Manager, select the Batteries category to expand it. There should ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found