Skip to content

[Bug] battery.status gives an error. #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Samuel-de-Oliveira opened this issue Feb 8, 2023 · 7 comments · May be fixed by #838
Open

[Bug] battery.status gives an error. #743

Samuel-de-Oliveira opened this issue Feb 8, 2023 · 7 comments · May be fixed by #838
Assignees

Comments

@Samuel-de-Oliveira
Copy link

Samuel-de-Oliveira commented Feb 8, 2023

Is in title, for any reason when I write battery.status the following error appears:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/plyer/utils.py", line 117, in __getattribute__
    result = getattr(object.__getattribute__(self, '_obj'), name)
  File "/usr/lib/python3.10/site-packages/plyer/facades/battery.py", line 42, in status
    return self.get_state()
  File "/usr/lib/python3.10/site-packages/plyer/facades/battery.py", line 49, in get_state
    return self._get_state()
  File "/usr/lib/python3.10/site-packages/plyer/platforms/linux/battery.py", line 81, in _get_state
    percentage = float(
ValueError: could not convert string to float: '0% (should be ignored'

Edit: I'm using Arch Linux

@misl6
Copy link
Member

misl6 commented Feb 11, 2023

Hi @Samuel-de-Oliveira !

Does this device have a battery?

@Samuel-de-Oliveira
Copy link
Author

Yes, it actually has.

About the device:

  • *company: * Multilaser
  • *Model: * pc312 Legacy

ℹ️ Multilaser is a Brazilian company that make home appliances, smartphones, computers and more.

I hope this usefully.

@misl6
Copy link
Member

misl6 commented Feb 12, 2023

Ok, since looks like we're unable to convert the output into a valid value, and I can't reproduce on my side, can you manually read the output from a console?

See: https://github.com/kivy/plyer/blob/master/plyer/platforms/linux/battery.py for the actual implementation.

@Samuel-de-Oliveira
Copy link
Author

Samuel-de-Oliveira commented Feb 15, 2023

Well, what I got in console is this:

this_image

so I tried to do something and I remove (commented) this following lines:

percentage = float(
      percentage.replace(',', '.')
)

and i Got this:

another_image

then I concluded that the library doesn't identify my laptop battery. I've tried solve it by myself but I don't have any idea what to do.

Copy link

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have the means to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Kivy's Control Tower Nov 10, 2023
@zencrab
Copy link

zencrab commented Apr 11, 2025

I think I know why @Samuel-de-Oliveira gets the ValueError. In linux, depending on the distribution, you may have the primary battery set to BAT1 instead of BAT0.

I checked the source code and it seems BAT0 is hardcoded to be the default battery for Linux platforms. However, for some distribution this is not the case, it seems Arch Linux is one of this distros (at least for me).

This is the line that gives that hardcodes the problem.
kernel_bat_path = join('/sys', 'class', 'power_supply', 'BAT0')

A similar issue was raise for psutil and it got fixed.

I have the same problem in my Arch Linux system, and if I check the primary battery with upower -e you can see that I get BAT1.

❯ upower -e
/org/freedesktop/UPower/devices/battery_BAT1
/org/freedesktop/UPower/devices/line_power_ACAD
/org/freedesktop/UPower/devices/DisplayDevice

If I forcefully check BAT0, it seems to exist but should be ignored as percentage property says:

❯ upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          (null)
  power supply:         no
  updated:              Thu 01 Jan 1970 01:00:00 BST (1744376463 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       unknown
    battery-level:       unknown
    percentage:          0% (should be ignored)
    icon-name:          '(null)'

While if check BAT1, then you can see it's the primary battery.

❯ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  ....
  power supply:         yes
  updated:              Fri 11 Apr 2025 14:00:52 BST (8 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              27.653 Wh
    energy-empty:        0 Wh
    energy-full:         33.532 Wh
    energy-full-design:  41.4279 Wh
    energy-rate:         7.7355 W
    voltage:             11.984 V
    charge-cycles:       701
    time to empty:       3.6 hours
    percentage:          82%
    capacity:            80.9405%
    technology:          lithium-ion
    charge-start-threshold:        75%
    charge-end-threshold:          80%
    charge-threshold-supported:    yes
    icon-name:          'battery-full-symbolic'
  History (charge):
    1744376380	82.000	discharging
  History (rate):
    1744376452	7.736	discharging
    1744376440	7.575	discharging
    1744376410	7.438	discharging
    1744376380	8.114	discharging
    1744376350	7.266	discharging

@misl6 I am comfortable to start working on this issue, could you please reopen it?

Copy link

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have the means to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@kuzeyron kuzeyron reopened this Apr 11, 2025
@zencrab zencrab linked a pull request Apr 11, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants