# Added the exact percentage of the battery capacity to the About section

**URL:** <https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214>\
**Category:** GameShell\
**Tags:** battery\
**Created:** [August 15, 2024, 12:14am UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214 "2024-08-15T00:14:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![knut](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/knut/32/10055_2.png) [@knut](https://forum.clockworkpi.com/u/knut)\
**Post date:** [August 15, 2024, 12:14am UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/1 "2024-08-15T00:14:56Z")

</div>

The **About** section is found here:

```auto
~/launcher/Menu/GameShell/10_Settings/About

```

And in the file ` __init__.py` I added the function:

```auto
def BatteryLevel(self):
    with open("/sys/class/power_supply/axp20x-battery/capacity") as f:
        battery = {}
        battery["key"] = "battery"
        battery["label"] = "Battery:"
        battery["value"] = f.read().replace("\n", "") + "%"
        self._AList["battery"] = battery

```

And in `GenList()` I added `,"battery"` to the list in the for-loop.  
Also, I entered the function `self.BatteryLevel()` in `Init()` before the line `self.GenList()`.

That’s it.  
Maybe you’ve fun adding this also.

–

Update: 2 typos now correct.

---

<div class="post-metadata">

**Author:** ![knut](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/knut/32/10055_2.png) [@knut](https://forum.clockworkpi.com/u/knut)\
**Post date:** [August 17, 2024, 6:35pm UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/2 "2024-08-17T18:35:37Z")

</div>

Because of the first likes I wanted to add that i can help you when you’ve got questions or other ideas.

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [September 23, 2024, 3:43pm UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/3 "2024-09-23T15:43:53Z")

</div>

Thanks, this looks like a very useful mod, but for some reason it didn’t work for me.  
I’m not very familiar with python, so I have a question where the function definition should go? I’ve tried adding it to the end of the file and inside the AboutPage class and both times I was getting stuck on the “loading” screen unless I removed the BatteryLevel function. Just removing “battery” from for-loop and commenting out self.BatteryLevel() didn’t help, so I guess that it’s something within the function itself that was causing my problem

---

<div class="post-metadata">

**Author:** ![knut](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/knut/32/10055_2.png) [@knut](https://forum.clockworkpi.com/u/knut)\
**Post date:** [September 23, 2024, 8:33pm UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/4 "2024-09-23T20:33:20Z")

</div>

Hello @edward ,

no problem. I explain in detail:

In the file there are the functions calculating or getting the data at first. So, I put the `BatteryLevel` from above between the `OsImageVersion` function and the `GenList` function.

In the `GenList`function I added the “battery”-string in this list:

```auto
for i,u in enumerate( ["processor","armcores","cpuscalemhz","features","memory","uname","launcher_ver","os_image_ver","battery"] )

```

At first I had it at the end like in the line above but I changed it after “cpuscalemhz” to see it without scrolling in the About section.

But to get it working the function `BatteryLevel` has to be called, so the `_AList` is filled with the battery data. This is done in the `Init` function. I put it between these:

```auto
    <...>
    self.OsImageVersion()
    self.BatteryLevel()
    self.GenList()
    <...>

```

That’s it:

1. The function `BatteryLevel` to generate the output for the About screen.
2. Call it in `Init`.
3. Add the “battery” string in `GenList` to show it at the place you want.

I hope you will get it work now.  
If not, just ask again. No problem.

–

**Additional thoughts:**

- Like everything in the Launcher, you’ve to use “Reload UI” to see changes in the battery level. But after playing a game, the launcher gets reloaded automatically, so it’s useful for me as it is.
- And I also added additional notifications to get an info when the battery is full, 80%, 60%, 40% and 20%, additionally to the “low battery” at 10 and 5%.

---

<div class="post-metadata">

**Author:** ![edward](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/edward/32/6761_2.png) [@edward](https://forum.clockworkpi.com/u/edward)\
**Post date:** [September 24, 2024, 3:27pm UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/5 "2024-09-24T15:27:31Z")

</div>

Thanks for explaining everything.

It took me a while to make it work, in the end all I needed is to pay some attention and not blindly copy your code, as it has 2 typos 😀

Just in case anybody else tries it: `battery{"label"]` should have opening square bracket instead of curly one (thanks vscode, as nano didn’t highlight this), and `self._Alist["battery"]` should have a capital L in AList.

---

<div class="post-metadata">

**Author:** ![knut](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/knut/32/10055_2.png) [@knut](https://forum.clockworkpi.com/u/knut)\
**Post date:** [September 26, 2024, 7:18pm UTC](https://forum.clockworkpi.com/t/added-the-exact-percentage-of-the-battery-capacity-to-the-about-section/14214/6 "2024-09-26T19:18:46Z")

</div>

> [@edward](#):
>
> Thanks for explaining everything.

You’re welcome.

> [@edward](#):
>
> It took me a while to make it work, in the end all I needed is to pay some attention and not blindly copy your code, as it has 2 typos 😀

I’m sorry, I edited the typos in the post above.
