Skip to content

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

Open
@ChriWt

Description

@ChriWt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions