Skip to content
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

Battery widget, "wrong" value on low battery notification #4876

Closed
2 tasks done
omulh opened this issue Jun 11, 2024 · 2 comments · Fixed by #4887
Closed
2 tasks done

Battery widget, "wrong" value on low battery notification #4876

omulh opened this issue Jun 11, 2024 · 2 comments · Fixed by #4887

Comments

@omulh
Copy link
Contributor

omulh commented Jun 11, 2024

Issue description

For the Battery widget, the value shown in the low level notification differs (by 1%) from the one shown in the widget itself.
This is not a bug per se, but something that is slightly annoying and should be fairly easy to solve.

After looking at the code, I think this is caused by the way the percentage is printed on the notification and on the widget. i.e. percent = int(status.percent * 100) is what goes to the notification, while something like '{percent:2.0%}'.format(percent=status.percent) is what goes to the widget.
One method always rounds down while the other rounds up and down.

I think this could be solved by changing one line in the poll function of the Battery class:

percent = int(status.percent * 100)
if percent < self.notify_below:
  if not self._has_notified:
    send_notification(
      "Warning",
      "Battery at {0}%".format(percent), <-- this line
      urgent=True,
      timeout=self.timeout,
    )

should change to:

"Battery at {0:2.0%}".format(status.percent),

Version

0.26.0

Backend

Wayland (experimental)

Config

Not relevant, imo

Logs

None

Required

  • I have searched past issues to see if this bug has already been reported, and it hasn't been.
  • I understand that people give their precious time for free, and thus I've done my very best to make this problem as easy as possible to investigate.
@tych0
Copy link
Member

tych0 commented Jun 11, 2024

Can you send a patch?

@omulh
Copy link
Contributor Author

omulh commented Jun 11, 2024

I'm afraid I don't know how to do that. I haven't used github for this kind of things yet. If you point me in the right direction I can give it a try

@tych0 tych0 closed this as completed in f883ce7 Jun 18, 2024
fjpavon pushed a commit to fjpavon/qtile that referenced this issue Jun 20, 2024
- Replace the 'percent' variable in the notification string with 'status.percent'
- Format the variable as % in the string
This should fix qtile#4876
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants