yasb icon indicating copy to clipboard operation
yasb copied to clipboard

[BUG] Battery State is None in Desktop PCs

Open ChriWt opened this issue 9 months ago • 0 comments

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 avatar May 07 '24 10:05 ChriWt