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

[BUG] Battery State is None in Desktop PCs #141

Open
ChriWt opened this issue May 7, 2024 · 0 comments
Open

[BUG] Battery State is None in Desktop PCs #141

ChriWt opened this issue May 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ChriWt
Copy link

ChriWt commented May 7, 2024

Expected Behavior

If the user is on a desktop PC rather than a laptop, psutil will not be able to detect a battery sensor and will return None.

Expected Behavior:

  1. Battery Present (Laptop): Returns an object with battery details like charge level and time remaining.
  2. Battery Absent (Desktop PC): Implement checks or use exception handling (try-except) to avoid AttributeError errors.

Current Behavior

Because the state of the battery is not verified, this triggers AttributeError exceptions (see yasb.log).

Possible Solution

This is the solution that I've implemented on my code:
Inside: "yasb\src\core\widgets\yasb\battery.py"

    alt_class = "alt" if self._show_alt_label else ""
    self._battery_state = psutil.sensors_battery()

    if self._battery_state is None:
        # With this the user is still able to customize the widget
        active_label.setProperty("class", f"label {alt_class} status-high")
        return

Steps to Reproduce

Run YASB on a Desktop PC

Context (Environment)

Platform: Windows 11
Python Version: 3.12.2
Psutil Version: 5.9.1
yasb.log

@ChriWt ChriWt added the bug Something isn't working label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant